Object Pool
Also known as Resource Pool Intent When objects are expensive to create and they are needed only for short periods of time it is advantageous to utilize the Object Pool pattern. The Object Pool provides a cache for instantiated objects tracking which ones are in use and which are available. Explanation Real world example In our war game we need to use oliphaunts, massive and mythic beasts, but the problem is that they are extremely expensive to create.
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.
Intent Ensure a class only has one instance, and provide a global point of access to it. Explanation Real-world example There can only be one ivory tower where the wizards study their magic. The same enchanted ivory tower is always used by the wizards. The ivory tower here is a singleton. In plain words Ensures that only one object of a particular class is ever created. Wikipedia says In software engineering, the singleton pattern is a software design pattern that restricts the instantiation of a class to one object.
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.