jeudi 12 mai 2016

Method with object vs parameter list in Repository Search. Violation of SRP?

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:

  1. 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.
  2. Even if object argument says it is less breaking, any change in search options will still require modification
  3. 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)

  1. Method remains intact and flexible to change without breaking much and requiring less work
  2. No unsightly, long parameter list in method signature
  3. 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?

Aucun commentaire:

Enregistrer un commentaire