Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

17
  • 1
    And of course, if you don't need to use the same doer again, that reduces to var result = new StuffDoer(initialParams).Calculate(extraParams);. Commented Nov 8, 2012 at 9:08
  • Calculate should be renamed to doStuff! Commented Nov 8, 2012 at 9:39
  • 1
    I would add that if you don't want to initialize (new) your class where you use it (probably you want to use a Factory) you have the option of creating the object somewhere else in you business logic and than pass the parameters directly to the single public method you have. The other option is to use a Factory and have on it a make method which gets the parameters and creates you object with all the params through it's constructor. Than you call your public method without params from wherever you want. Commented Nov 8, 2012 at 10:30
  • 2
    This answer is overly simplistic. Is a StringComparer class which you use as new StringComparer().Compare( "bleh", "blah" ) well designed? What about creating state when there is entirely no need to? Okay the behavior is well encapsulated (well, at least to the user of the class, more on that in my answer), but that doesn't make it 'good design' by default. As to your 'doer-result' example. This would only make sense if you would ever use doer separate from result. Commented Nov 8, 2012 at 12:15
  • 1
    It's not one reason to exist, it's one reason to change. The differnce might seem subtle. You have to understand what that means. It will never create one method classes Commented Nov 8, 2012 at 13:03