Reputation: 1994
What do we achieve by creating AbstractFactory when we already have Factory?
I mean by using Factory also we can directly create concrete objects than why should we use AbstractFactory and get Factory and than create object.
Upvotes: 0
Views: 35
Reputation: 1771
Factory Pattern:
Createobject through inheritance
Produceonly one product
Implementscode in the abstract creator that make use of the concrete type that sub class produces.
Abstract Factory Pattern:
Createobject through composition
Produce families ofproducts
Concretefactories implements factory method to create product
Factory pattern: The factory produces IProduct-implementations
Abstract Factory Pattern: A factory-factory produces IFactories, which in turn produces IProducts
Upvotes: 0
Reputation: 8163
A factory is there for creating concrete objects. If you have multiple implementations of your object, you often also need multiple implementations of the factory interface, which some part of the code will use without knowing which concrete factory it was. Hence you need AbstractFactory.
Upvotes: 1