Thursday, May 2, 2019

Wrapper objects vs many parameters as method parameters

Hi,

What do you guys think about creating new classes for "request" objects for methods vs not wrapping the parameters and having multiple parameters in method definitions?

To clarify, I'm talking about for example a method in a Manager (business layer) class. It currently has eight parameters, and I'm debating whether to keep it as is, or whether to create a wrapper object for the sole purpose of using it to pass the parameters to the method in a "less parameters in method definition" kind of way.

Basically it's:

MethodInManager(string a, string b, string c, string d, string e, string f, string g, string h) 

vs

public class MethodInManagerRequest { string a; string b; // etc } MethodInManager(MethodInManagerRequest request) 

Where the MethodInManagerRequest doesn't serve any purpose other than wrapping the parameters which are then immediately unwrapped inside the method.

Also, if we define a class like MethodInManagerRequest, where should it be defined? We have an assembly where our Model classes are defined, but I'm not sure if wrapper classes like this belong there? Would it be okay to define them inside the assembly where the managers live? In that case, we might have for example an assembly called BusinessLogic, and it could include folders called: "Managers", "Requests", "Responses" or something like that, where the Requests and Responses are wrapper objects that are parts of the manager method definitions.

All thoughts appreciated :)

Wrapper objects vs many parameters as method parameters Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team