Abstract Factory Pattern

Budhdi Sharma
AndroidPub
Published in
3 min readDec 11, 2019

--

Abstract Factory is a creational design pattern, which solves the problem of creating entire product families without specifying their concrete classes.

Abstract Factory defines an interface for creating all distinct products but leaves the actual product creation to concrete factory classes. Each factory type corresponds to a certain product variety.

The client code calls the creation methods of a factory object instead of creating products directly with a constructor call (new operator). Since a factory corresponds to a single product variant, all its products will be compatible.

Client code works with factories and products only through their abstract interfaces. It allows the same client code to work with different products. You just create a new concrete factory class and pass it to the client code.

Define an interface or abstract class for creating families of related (or dependent) objects but without specifying their concrete sub-classes.
That means Abstract Factory lets a class returns a factory of classes. This is why? Abstract Factory Pattern is one level higher than the Factory Pattern.
An Abstract Factory Pattern is also known as Kit.

Advantage

  • Isolates the client code from concrete (implementation) classes.
  • It eases the exchanging of object families.
  • It promotes consistency among objects.

--

--

Budhdi Sharma
AndroidPub

As an AOSP/AAOS/XROS/RTOS Engineer, I specialize in creating robust framework and system applications that seamlessly integrate with embedded systems