(or about) Wed, 09 Jul 2003 14:09:00 GMT, :
>I can prevent my high level components from having a dependency on lower
>level components, by publishing a series abstractions, and depending solely
>on those. The lower level components of course then implement these
>What creational techniques should I consider to avoid thwarting this? i.e.
>My high level package is now bereft of any dependency on the lower level
>component, but how do I instanciate the concretions without giving my higher
>level component knowledge of the lower level one?
The traditional response is to use an AbstractFactory to create the
objects. Frankly, this is often a giant pain. Another approach is to
create a Cloneable prototype.
Shape squarePrototype = new Square();
Shape circlePrototype = new Circle();
Shape s = squarePrototype.clone();
This can work OK in languages like C++, but Java may force you to
group all the prototypes into a single class, thus creating coupling
Another possibility is to have a bunch of static functions that create
Again, in C++ this works fine, but in Java you have to place the
static functions into a class, and that can cause coupling woes.
In the end, it's sometimes just better to create the classes directly
than it is to hunt for some obtuse form of indirection. I suggest you
wait until you feel pain before you use a Factory, or one of the other
Robert C. Martin | "Uncle Bob"
PO Box 5757 | Tel: (800) 338-6716
565 Lakeview Pkwy | Fax: (847) 573-1658 | www.objectmentor.com
Suite 135 | | www.XProgramming.com
Vernon Hills, IL, | Training and Mentoring | www.junit.org
60061 | OO, XP, Java, C++, Python |