Skip to main content
1 of 2
User
  • 1.6k
  • 2
  • 16
  • 31

Pass in single settings object vs multiple setter methods?

Working with C++. Suppose I have a class BoxFilter. The class is used to filter boxes which have properties such as height, width, depth, weight, etc. The filter might have something like MaxWidth so that boxes with a width greater than MaxWidth would not pass the filter. Usage would be something like (C#-style pseudocode):

IBoxFilter filter = new BoxFilter();

foreach(Box box in boxes)
{
  if(filter.PassesFilter(box))
     // do something  
}

(sorry for the C# example but I think it's easier to understand)

In setting up the filter object I need to configure the settings of the filter. The filter currently has 7 properties although it could get more over time. I'm debating whether the filter class should have multiple setters such as SetWidthMax(), SetWidthMinimum(), SetHeightMax(), SetHeightMinimum(), etc or should I create a BoxFilterSettings object/struct and then have a single method on the box filter class called SetSettings(BoxFilterSettings settings)?

User
  • 1.6k
  • 2
  • 16
  • 31