Factory Pattern


There are 2 factory patterns as described by the Gang of Four which are the factory method and abstract factory the main difference is the factory method is a single method and an abstract factory is an object.

  • The factory method is just a method, it can be overridden in a subclass, whereas the abstract factory is an object that has multiple factory methods on it.
  • The Factory Method pattern uses inheritance and relies on a subclass to handle the desired object instantiation

Factory Method

The factory pattern is used to replace class constructors, abstracting the process of object generation so that the type of the object instantiated can be determined at run-time.

Abstract Factory

The abstract factory pattern is used to provide a client with a set of related or dependent objects. The “family” of objects created by the factory are determined at run-time.