Also known as Borg Intent Enforces a behaviour like sharing the same state amongst all instances. Class diagram 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.
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. In plain words Multiton pattern ensures there are a predefined amount of instances available globally. Wikipedia says In software engineering, the multiton pattern is a design pattern which generalizes the singleton pattern.
Object Mother
Object Mother Define a factory of immutable content with separated builder and factory interfaces. Class diagram 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 Credits Answer by David Brown to the stackoverflow question: What is an ObjectMother? c2wiki - Object Mother Nat Pryce - Test Data Builders: an alternative to the Object Mother pattern
Intent Create hierarchy of objects and new objects using already existing objects as parents. Class diagram Applicability Use the Property pattern when When you like to have objects with dynamic set of fields and prototype inheritance Real world examples JavaScript prototype inheritance
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. Real-world example Remember Dolly? The sheep that was cloned! Let’s not get into the details but the key point here is that it is all about cloning.
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. Programmatic Example Below is a Customer Class 1public class Customer { 2 3 private final String id; 4 private final String name; 5 6 public Customer(String id, String name) { 7 this.
Step Builder
Intent An extension of the Builder pattern that fully guides the user through the creation of the object with no chances of confusion. The user experience will be much more improved by the fact that he will only see the next step methods available, NO build method until is the right time to build the object. Class diagram Applicability Use the Step Builder pattern when the algorithm for creating a complex object should be independent of the parts that make up the object and how they’re assembled the construction process must allow different representations for the object that’s constructed when in the process of constructing the order is important.
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 There is a class for hero statistics in a role-playing game. The statistics contain attributes such as strength, intelligence, and luck. The statistics of different heroes should be equal when all the attributes are equal.