The Gang of Four (GoF) are Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. They wrote Design Patterns: Elements of Reusable Object-Oriented Software. In it, they documented 23 classic software design patterns.
There are five creational design patterns - they cover the instantiation of objects.
Singleton
There can only be one instance.
Useful for when more than one copy of an object or class would break your system.
Factory Method
A factory is an interface for creating an object. Its subclasses determine the shape of the instantiated object.
Useful for when the creation of some objects is complex enough to be abstracted and those objects have overlapping implementation details.
Abstract Factory
Essentially a factory of factories - a list of creation methods for a group of factories.
Useful for factories need to be grouped together.
Builder
A list of methods for constructing parts of an object.
Useful for when you have so many optional parameters that passing them through a factory is error-prone.
Prototype
New objects are created by copying an existing object, inheriting characteristics from the parent object.
More efficient for complex object creation. JavaScript uses prototypical inheritance.
Top comments (0)