Friday, July 08, 2005

Abstract Factory And Factory Method

Many developers new to design patterns have this confusion with regard to Abstract Factory and Factory Method. The Factory Method is used in conjunction with Abstract Factory in most cases. The confusion is the term "factory" in the name. Abstract factory is grouping of a family of concrete classes by having a single Abstract class that represents the family. Hence type encapsulation occurs by using this pattern. Factory method really instantiates the appropriate concrete class at runtime and therefore a call to the method returns a concrete type at runtime. Therefore most concrete classes in an Abstract Factory can consists of factory methods which then return the appropriate type needed for the client.


Abstract Factory

The system shall be "platform-independent"
The system shall be independent of how its constituent pieces are created, composed, and represented.
The system shall be configured with one of multiple families of products.
A family of products designed to be used together shall have their relationship constraints enforced.
"case" statements are a maintenance nightmare - they shall be avoided


Factory Method

A subsystem shall not have the "type" of component it is responsible for creating hard-wired.
The system shall be "open for extension, but closed for modification".

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home