1.1 What is Abstract Factory Pattern?
- Abstract Factory is a creational design pattern that lets you produce families of related objects without specifying their concrete classes
- This pattern works around a super-factory which creates other factories. This factory is called factory of factories
1.2 Problem
Imagine that you’re creating a furniture shop simulator. Your code consists of classes that represent:
a) A family of related products, say: Chair + Sofa + Coffee Table.
b) Several variants of this family. For example, products Chair + Sofa + Coffee Table are available in these variants: Modern, Victorian.
You need a way to create individual furniture objects so that they match other objects of the same family. Customers get quite mad when they receive non-matching furniture.

1.3 Solution

Step 1: Declare interfaces for each distinct product of the product family. (Chair.java, Sofa.java , CoffeeTable.java)
Step 2: Create Concrete Products of these interfaces (ModernChair.java, VictorainChair.java, ModernSofa.java , VictorianSofa.java, ModernCoffeeTable.java, VictorianCoffeeTable.java)
Step 3: Declare the Abstract Factory (FurnitureFactory.java)—an interface with a list of creation methods for all products that are part of a product family (createSofa(), createChair(), createCoffeeTable()). These method should return abstract product type.
Step 4: For each variant of a product family, we create a separate factory class from FurnitureFactory interface (VictorianFurnitureFactory.java, ModernFurnitureFactory.java)
Step 5: Create a factory creator class to get factories by passing an information such as design (FactoryCreator.java)
1.4 When is Abstract Factory Used?
- The application needs to create multiple family of products
- When you want to provide a library of objects that does not show implementations but only reveals interfaces.


You must be logged in to post a comment.