Home  /  Questions  /  Question



250   96.9
Mar 08, 2012


Factory pattern Vs Abstract Factory pattern

I want to know what are the difference between them



80   96.3
May 21, 2012

Real Life Example. (Easy to remember)

Factory

Imagine you are constructing a house and you approach a carpenter for a door. You give the measurement for the door and your requirements, and he will construct a door for you. In this case, the carpenter is a factory of doors. Your specifications are inputs for the factory, and the door is the output or product from the factory.

Abstract Factory

Now, consider the same example of the door. You can go to a carpenter, or you can go to a plastic door shop or a PVC shop. All of them are door factories. Based on the situation, you decide what kind of factory you need to approach. This is like an Abstract Factory.

 1 comment
 
I created an account solely for the purpose of thanking you for those perfect analogies. So thank you :) --- Charlie Malbaurn  Jun 05, 2012

60   95.3
Apr 05, 2012
Factory Pattern:

1. Createobject through inheritance

2. Produceonly one product

3. Implementscode in the abstract creator that make use of the concrete type that sub class produces.


Abstract Factory Pattern:

1. Createobject through composition

2. Produce families ofproducts

3. Concretefactories implements factory method to create product


70   95.9
Mar 13, 2012

Factory: A factory that creates objects that derive from a particular base class.

Abstract factory: A factory that creates other factories, and these factories in turn create objects derived from base classes. You do this because you often don't just want to create a single object (as with Factory method) - rather, you want to create a collection of related objects.