Factory pattern is an OOPS way of refering to creating objects with specific functionality and encapsulating the creation process so as to not expose the process to the client.
Factory can be anything that creates an object. In JS/TS world, it can be a function or a class.
Factories make it easier to swap or extend the creation logic without changing client code.
Adding new types of similar objects is simpler, as you can modify existing factory for object creation.
- Product Interface/Abstract Class: Defines the type of objects the factory will create.
- Concrete Products: Specific implementations of the product interface.
- Factory Interface/Abstract Class: Declares a method for creating objects.
- Concrete Factory: Implements the creation logic to instantiate specific products.