Abstract Factory Design Pattern

Abstract Factory patterns acts a super-factory which creates other factories. This pattern is also called as Factory of factories. In Abstract Factory pattern an interface is responsible for creating a set of related objects, or dependent objects without specifying their concrete classes.

The essence of the Abstract Factory Pattern is to "Provide an interface for creating families of related or dependent objects without specifying their concrete classes."

UML Driagram

Figure 1: UML Class Diagram for Abstract Design Pattern

Interpretation
Class/Interface Desription
Abstract Factory An interface for creating Concrete Factory. This is super factory
Concrete Factory Implements Abstract Factory interface to create the factory.
Abstract Product An interface for creating type of product.
Concrete Product Implements Abstract Product interface to create the product.
Client This is class that uses/consume the abstract factory

Sample Implementation
Let's create an application that implements abstract factory pattern: An application that inquires a car factory from a dealer and the car or automobile factory will return 2 types of car through the dealer:
  1. Economy Car
  2. Luxury Car
Download Source Code


The Project Structure


Figure 2: The project structure of Car/Auto Abstract Design Pattern

The UML Class Diagram


Figure 3: The Car Factory Class Diagram

Mapping of Car Factory Interface and Classes to Abstract Design Pattern
Class/Interface Car/Automobile Factory
Abstract Factory IFactory
Concrete Factory ToyotaFactory and FordFactory
Abstract Product IAutomobile
Concrete Product Toyota(CorollaAxioEconomy, ToyotaAvalonLuxury) and Ford(Ford300Economy, FordCougarLuxury)
Client Program, XCarDealer

Open/Closed Principle (OCP)
In OOP SOLID design, we should always maintain the OCP principle. The xCarDealer class is responsible for maintaining this (in Builder Design Pattern it acts as the Director). Just inject the Factory and it will give you the results.

The Codes

The Factories
IFactory.cs
ToyotaFactory.cs
FordFactory.cs

The Products
IAutomobile.cs
CorollaAxioEconomy.cs
ToyotaAvalonLuxury.cs
Ford300Economy.cs
FordCougarLuxury.cs

The Clients
XCarDealer.cs
Program.cs

The Output

Conclusion
Abstract Factory Design Pattern is usually used in Game Production Industry because of its powerful inheritance capability.

Well! I hope I was able to reduce the complexities in explaining this Design Pattern. Thank you for your time. Your comments are valuable to me.