Context object
Name / classification Context Object Also known as Context, Encapsulate Context Intent Decouple data from protocol-specific classes and store the scoped data in an object independent of the underlying protocol technology. Explanation Real-world example This application has different layers labelled A, B and C with each extracting specific information from a similar context for further use in the software. Passing down each pieces of information individually would be inefficient, a method to efficiently store and pass information is needed.
Intent The purpose of the Converter pattern is to provide a generic, common way of bidirectional conversion between corresponding types, allowing a clean implementation in which the types do not need to be aware of each other. Moreover, the Converter pattern introduces bidirectional collection mapping, reducing a boilerplate code to minimum. Explanation Real world example In real world applications it is often the case that database layer consists of entities that need to be mapped into DTOs for use on the business logic layer.
Dependency Injection
Intent Dependency Injection is a software design pattern in which one or more dependencies (or services) are injected, or passed by reference, into a dependent object (or client) and are made part of the client’s state. The pattern separates the creation of a client’s dependencies from its own behavior, which allows program designs to be loosely coupled and to follow the inversion of control and single responsibility principles. Explanation Real world example
Also known as Simple Factory Static Factory Method Intent Providing a static method encapsulated in a class called the factory, to hide the implementation logic and make client code focus on usage rather than initializing new objects. Explanation Real-world example Imagine an alchemist who is about to manufacture coins. The alchemist must be able to create both gold and copper coins and switching between them must be possible without modifying the existing source code.
Factory Kit
Also Known As Abstract-Factory Intent Define a factory of immutable content with separated builder and factory interfaces. Explanation Real-world example Imagine a magical weapon factory that can create any type of weapon wished for. When the factory is unboxed, the master recites the weapon types needed to prepare it. After that, any of those weapon types can be summoned in an instant. In plain words Factory kit is a configurable object builder, a factory to create factories.
Factory Method
Also known as Virtual Constructor Intent Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses. Explanation Real-world example Blacksmith manufactures weapons. Elves require Elvish weapons and orcs require Orcish weapons. Depending on the customer at hand the right type of blacksmith is summoned. In plain words It provides a way to delegate the instantiation logic to child classes.
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