The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
January 2002



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Abstract Factories vs. Abstract Methods

Posted by Matt Gerrans on January 25, 2002 at 5:12 PM

My earlier comments were not to discount the methodolgy, but merely to point out that it looks more to me like you are using perhaps factory methods, but not necessarily an abstract factory pattern. Therefore I would avoid using the name abstract factory in order to avoid confusing readers of the code.

I think the abstract factory is probably used pretty rarely in practice, in really complicated scenarios. Just look at the example given in Design Patterns or any of other books about design patterns, such as Applied Java Patterns by Stelting and Massen (which has a pretty weak example, if you ask me) and Bruce Eckel's Thinking in Patterns with Java (which has a better example). Eckel's book is available free from his web site. These examples show a complicated situation, where you need to create concrete factories (based on the abstract factory), which in turn are used to create whole families of objects.

I think in this database problem all that is needed is a factory method. Based on whatever pertinent criteria, it creates a database object of some concrete flavor that can then be used. The concrete database objects are all based on some database interface and the application uses it independent of which actual database implementation it is referring to.


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us