I have a debate with my peer on whether it is good practice or not to either encapsulate a repository method's search options in an object or in a (potentially growing) parameter list.
In summary, psuedocode would be:
SearchItems(int id,string name,int statusId)
Vs
class SearchOptions
{
/*
For illustration purposes, I intentionally made the, otherwise private fields public.
Under normal circumstances, they would be private with their respective accessors or mutators or properties for C#
*/
public int id;
public string name;
public int statusId;
}
SearchItems(SearchOptions filter)
{
//Rest of code here
}
Argument for parameter list are:
- That the search has the single responsibility of getting only the results required at that point. If search requirements should change,a new method with the specific function should be written.
- Even if object argument says it is less breaking, any change in search options will still require modification
- It is friendlier to integrating across platforms (e.g. Java service backend to WCF service backend due to simplicity of method signature)
Argument for having an object to hold filter options are: (my argument)
- Method remains intact and flexible to change without breaking much and requiring less work
- No unsightly, long parameter list in method signature
- Interfaces are left intact, adding more weight to less breaking changes
What would be considered good practice? And do the arguments hold(both sides) Or is this subjective?