From: Olaf K. <ok...@ab...> - 2002-06-28 07:29:57
|
Paul Jackson wrote: > > The approach we have been taking is to extend a Factory with a MockFactory have a static Factory.setInstance(Factory f) that allows us to setup the MockFactory as the real factory. > > That is assuming that we use a singleton pattern to return the Factory (or MockFactory) with the static Factory.instance() method. > > Is this the best approach or is there a better one? It's a valid approach, if there is a better one depends upon your needs. I personally prefer "building" fully configured Objects rather than leaving configuration to them - thus needing factory singletons to callback to the environment. After all, singletons are the object oriented globals. Sorry, I don't have the reference to "Singletons Are Evil" at hand. Probably somebody else could jump in. If you build configured objects, a builder (or anything else constructing them - I'm not necessarily talking exclusively about the GOF-Builder here) can configure an object one way, the testcode will configure them differently. This way testcode doesn't need to bother with factories, messing up singletons with the need for cleanups later and unpredictable side effects, if this cleanup is forgotten. Olaf -- abstrakt gmbh, Behringstrasse 16b, 22765 Hamburg Tel: +49-40-39804630, Fax: +49-40-39804639 http://www.abstrakt.de/ |