Abstract Class Factory Method

udaiveer singh
Code Wave
Published in
2 min readJun 23, 2019

In the last post, we talked about Method Factory Pattern, but his one is about its “big brother”, the Abstract Class Factory Method.

What is the abstract class factory method pattern?

This pattern is something that uses an interface to delegate out the creation of a family of related products.

What is the difference between Method Factory and Abstract Class Factory?

  • The Methods Factory Patter uses inheritance plus an abstract method to delegate the creation of the objects to its subclasses.
  • The Abstract Class pattern uses an interface and delegates out the creation of multiple products to different factories.

How to choose between Method Factory or Abstract Factory Pattern?

  • The method factory pattern is simpler to implement and is usually more memory efficient, but it has
  • Abstract Factory method is good at dealing with families of products that have similar product lines. ie. If you are writing a First person shooter game you can have 3 groups (ArmyFactory, NavyFactory, Space Force ); each task force can support 3 types of units (Human Unit<I>, Land Unit<I>, Stealth Unit<I>). The application for each player can only load one group at player login. The code in your application only needs to deal with the 3 interfaces now (Human, Land, Stealth).

sources:

previous post:

--

--