[rfc] MethodObject or CommandObject pattern and reconfigure.py
Martin Pool
mbp at canonical.com
Wed Aug 5 00:37:42 BST 2009
2009/8/5 Robert Collins <robert.collins at canonical.com>:
> On Fri, 2009-07-24 at 15:37 +1000, Martin Pool wrote:
>>
>>
>> * If the only interface you want to present is "do this action" and
>> there's no obvious object identity that callers would be interested
>> in, make it a function not an object. The function can always become
>> a factory for objects later, whether or not that's disclosed.
>
> Objects often make unit testing easier, even in the case where the
> client API is going to be very narrow. I think its worth saying that
> these are factors to consider, but I would hesitate to make them rules.
That could possibly still be a reason to have the public interface
just be a function that constructs and uses the object; you could then
construct the object directly for unit testing.
"Make it an object because that makes testing easier" as a guideline
seems barely helpful. One needs to have some specific need to factor
it that way, or at least a reasonable suspicion there will be one.
They might include -
* As a specific case of extensibility through template methods you
can hook them to observe them being called
* Objects that accumulate state in instance variables can let you
observe or poke at that test as you go along - but I think normally
those are not very nice tests.
* Objects that act as their own Result or Reporter give the test rich
structured results to examine - but I think it's better to just have a
Result or Reporter separate from the implementation.
--
Martin <http://launchpad.net/~mbp/>
More information about the bazaar
mailing list