1

I am debating the pros and cons of a couple of utility classes I have. The classes have a couple of properties which are set prior to calling the class methods. However, I was wondering if there are any cons to this approach rather than sending a variable along with the method call? There are typically only one or two methods in these classes.

Thank you.

3

If I'm reading the question correctly, you're asking whether to use

obj.Foo(bar);

or

obj.Bar = x;
obj.Foo();

Most of the time, the former is better, because it makes it much clearer that bar is required for the Foo() operation, it makes it impossible (in a statically typed language) to forget to provide a bar value, and it makes the behavior of Foo() easier to reason about when each call only depends on its parameters and not the "state of the world" at the time it was called.

Not the answer you're looking for? Browse other questions tagged or ask your own question.