DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Factory Method
Francesco Ciulla
Francesco Ciulla

Posted on

Factory Method

Factory Pattern

Delegate object creation at runtime

Creational Design Pattern

GitHub Link: https://github.com/FrancescoXX/Design-Patterns-Factory-Method-Javascript


The Factory Method describes how to solve the recurring problem to design flexible, reusable, object-oriented software.

We need objects, created at runtime, that are easier to implement, change, test, and reuse.


Alt Text

⚑️Problem idea

Create different characters in our game


πŸ’‘Intent

  • Define an interface for creating an object, but let subclasses decide which class to instantiate
  • It lets a class defer instantiation to subclasses

πŸ”§ Apply when

  • Class can't expect the type of object it must create
  • Subclass must decide what types of objects are create

βœ…Pro

  • Delegate object creation
  • Hook for subclasses
  • Base class can provide a default implementation

πŸ† Great for

  • Delegate object creation at runtime
  • When we don't know what type of class we need to create

GitHub Link: https://github.com/FrancescoXX/Design-Patterns-Factory-Method-Javascript

Top comments (0)

Take a look at this:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. πŸ›