Skip to main content
Curiously Recurring Template Pattern

Name / classification

Curiously Recurring Template Pattern

Also known as

Recursive Type Bound, Recursive Generic

Intent

Allow derived components to inherit certain functionalities from a base component that are compatible with the derived type.

Explanation


iluwatarAbout 2 minStructuralExtensibilityInstantiation
MonoState

Also known as

Borg

Intent

Enforces a behaviour like sharing the same state amongst all instances.

Class diagram

MonoState

Applicability

Use the Monostate pattern when

  • The same state must be shared across all instances of a class.
  • Typically this pattern might be used everywhere a Singleton might be used. Singleton usage however is not transparent, Monostate usage is.
  • Monostate has one major advantage over singleton. The subclasses might decorate the shared state as they wish and hence can provide dynamically different behaviour than the base class.

iluwatarLess than 1 minuteCreationalInstantiation
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

Step Builder Pattern

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