Skip to main content
CRTP

Also known as

  • Recursive Type Bound
  • Recursive Generic
  • Static Polymorphism
  • Mixin Inheritance

Intent

Curiously Recurring Template Pattern (CRTP) is used to achieve a form of static polymorphism by having a class template derive from a template instantiation of its own class, allowing method overriding and polymorphic behavior at compile time rather than at runtime.


iluwatarAbout 3 minStructuralExtensibilityIdiomInstantiation
MonoState

Also known as

Borg

Intent

Monostate is an alternative approach to achieving a singleton-like behavior in object-oriented design. It enforces a unique behavior where all instances of a class share the same state. Unlike the Singleton pattern, which restricts a class to a single instance, Monostate allows for multiple instances but ensures they all have a shared state.


iluwatarAbout 3 minCreationalInstantiation
Multiton

Also known as

Registry

Intent

Ensure a class only has a limited number of instances and provide a global point of access to them.

Explanation

Real-world example

The Nazgûl, also called ringwraiths or the Nine Riders, are Sauron's most terrible servants. By
definition, there's always nine of them.


iluwatarAbout 2 minCreationalInstantiation
Object Mother

Object Mother

It is used to define a factory of immutable content with separated builder and factory interfaces.

Class diagram

Object Mother

Applicability

Use the Object Mother pattern when

  • You want consistent objects over several tests
  • You want to reduce code for creation of objects in tests
  • Every test should run with fresh data

iluwatarAbout 2 minCreationalInstantiation
Property

Intent

Create hierarchy of objects and new objects using already existing
objects as parents.

Explanation

Real-world example

In the mystical land of "Elandria", adventurers can harness the power of ancient relics to customize their abilities. Each relic represents a unique property or skill. As adventurers explore, they discover and integrate new relics, dynamically enhancing their skills based on the relics they possess.


iluwatarAbout 1 minCreationalInstantiation
Prototype

Intent

Specify the kinds of objects to create using a prototypical instance, and create new objects by
copying this prototype.

Explanation

First, it should be noted that the Prototype pattern is not used to gain performance benefits. It's only
used for creating new objects from prototype instances.


iluwatarAbout 2 minCreationalGang Of FourInstantiation
Registry

Intent

Stores the objects of a single class and provide a global point of access to them.
Similar to Multiton pattern, only difference is that in a registry there is no restriction on the number of objects.

Explanation

In Plain Words

Registry is a well-known object that other objects can use to find common objects and services.


iluwatarLess than 1 minuteCreationalInstantiation
Step Builder

Explanation

The Step Builder pattern is a creational design pattern used to construct a complex object step by step. It provides a fluent interface to create an object with a large number of possible configurations, making the code more readable and reducing the need for multiple constructors or setter methods.


iluwatarAbout 2 minCreationalInstantiation
Value Object

Intent

Provide objects which follow value semantics rather than reference semantics.
This means value objects' equality is not based on identity. Two value objects are
equal when they have the same value, not necessarily being the same object.

Explanation

Real-world example


iluwatarAbout 1 minCreationalInstantiation