DEV Community

Cover image for Gang of Four Design Patterns in Memes - Creational
Abbey Perini
Abbey Perini

Posted on

Gang of Four Design Patterns in Memes - Creational

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.

There can only be one. A Scottish warrior from the movie Highlander

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.

A factory worker sees three triangles and one circle on a conveyor belt. They say

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.

Every friend group: My Hero Academia characters labeled

Useful for factories need to be grouped together.

Builder

A list of methods for constructing parts of an object.

Homer Simpson at the nuclear power plant operation board looking panicked labelled

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.

One person holding an object says

More efficient for complex object creation. JavaScript uses prototypical inheritance.

Top comments (0)