Jigar Naik
Jigar Naik

Reputation: 1994

Why there is a need for creating AbstractFactory when there is Factory

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

Answers (2)

Gul Ershad
Gul Ershad

Reputation: 1771

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

Factory pattern: The factory produces IProduct-implementations

Abstract Factory Pattern: A factory-factory produces IFactories, which in turn produces IProducts

Upvotes: 0

kutschkem
kutschkem

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

Related Questions