0

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.

Jigar Naik
  • 1,946
  • 5
  • 29
  • 60
  • Possible duplicate of [Differences between Abstract Factory Pattern and Factory Method](https://stackoverflow.com/questions/5739611/differences-between-abstract-factory-pattern-and-factory-method) – Johnny Feb 28 '18 at 14:53

2 Answers2

1

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.

kutschkem
  • 7,826
  • 3
  • 21
  • 56
0

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

Gul Ershad
  • 1,743
  • 2
  • 25
  • 32