Skip to content

In the Abstract Factory pattern, we get rid of if-else block and have a factory class for each sub-class. Then an Abstract Factory class that will return the sub-class based on the input factory class. At first, it seems confusing but once you see the implementation, it’s really easy to grasp and understand the minor difference between Factory a…

Notifications You must be signed in to change notification settings

Design-pattrns/Abstract-Factory-Pattern

Repository files navigation

AbstractFactoryPattern

Note

The Abstract Factory design pattern is similar to the Factory Method design pattern just discussed. Both solve the problem of how to create objects that conform to an abstract interface in a way that moves the responsibility for creating the objects outside of the client. The client decides when the objects are created but another class outside of the client decides what classes are created.

What distinguishes the Abstract Factory design pattern from the Factory Method design pattern is that the Abstract Factory design pattern is designed to create families of related objects. The key word here is family. Factory Method is designed to create one type of object. Abstract Factory is designed to create a family of related products.

Diagrams

  • Base class diagram

alt text

About

In the Abstract Factory pattern, we get rid of if-else block and have a factory class for each sub-class. Then an Abstract Factory class that will return the sub-class based on the input factory class. At first, it seems confusing but once you see the implementation, it’s really easy to grasp and understand the minor difference between Factory a…

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published