Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it OK to have a class with just properties for refactoring purposes?

I have a method that takes 30 parameters. I took the parameters and put them into one class, so that I could just pass one parameter (the class) into the method. Is it perfectly fine in the case of refactoring to pass in an object that encapsulates all the parameters even if that is all it contains.

like image 859
Xaisoft Avatar asked Nov 10 '11 17:11

Xaisoft


1 Answers

That is a great idea. It is typically how data contracts are done in WCF for example.

One advantage of this model is that if you add a new parameter, the consumer of the class doesn't need to change just to add the parameter.

As David Heffernan mentions, it can help self document the code:

FrobRequest frobRequest = new FrobRequest {     FrobTarget = "Joe",     Url = new Uri("http://example.com"),     Count = 42, }; FrobResult frobResult = Frob(frobRequest); 
like image 89
McKay Avatar answered Nov 11 '22 13:11

McKay