Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Source

https://refactoring.guru/design-patterns/factory-method

Important:

  1. Provides an interface for creating objects in a supper class, but allows subclasses to alter the type of objects that will be created
  2. Creates an instance of several derived classes

Description

Structure

alt tag

How to use

  1. Use the Factory Method when you don’t know beforehand the exact types and dependencies of the objects your code should work with.
  2. Use the Factory Method when you want to provide users of your library or framework with a way to extend its internal components.
  3. Use the Factory Method when you want to save system resources by reusing existing objects instead of rebuilding them each time.

Running

python main.py
python example.py