Three types of templates can be distinguished: generating, structural and behavioral. We list the main design patterns for each of them.
These patterns allocate the instance process. With the help of them, the system ceases to depend on the method of forming a composition and representing objects.
Prototype. Such a template sets the types of objects created through a specimen-prototype. Moreover, by copying the prototype, the pattern forms new objects. When using this template, you can move away from implementation and adhere to the principle of “programming through interfaces”. In the role of a returning type, the specified interface/abstract class at the top of the hierarchy acts. At the same time, classes-leaders can set up in this place the heir performing the implementation of this type. In other words, the prototype allows you to create an object by cloning, and not using a designer.
Factory (factory). This is not considered a pattern in the strict sense of the word. It will be more correct to designate Factory as an approach, in which the logic of creating objects is included in a separate class.
Factory method. The template, which will determine the general interface for the formation of objects in the superclass. This method gives subclasses the opportunity to change the type of objects created.
Abstract factory (abstract factory). This is a generating design pattern that provides an interface to create families of interconnected or interdependent objects, without the direct specification of their specific classes. The implementation of such a template is ensured by creating an abstract class Factory. This class acts as an interface for creating components of the system (say, in relation to the window interface, it can form windows and buttons). After all this, classes that implement this interface are written.
Loner (Singleton). Another generating pattern. With the help of it, the presence of a single copy of the class with a global access point in a single -back application is ensured.
Builder (Builder). A useful generating pattern, which, in fact, is the method of creating an integral object. It differentiates a complex object for design and representation. Thanks to this, when performing the same design operation, you can get different ideas.
Such templates are determined by all kinds of high levels of complexity, which make changes to the interface of already created objects or its implementation. This allows you to simplify the development process and make the program more optimized.
The templates included in this variety facilitate the design due to the fact that they reveal the simplest method of realizing relations between subjects.
Bridge (Bridge). It is used in the design of the software. He shares abstraction and implementation in such a way that they can change independently. This pattern works through incapsulation, aggregation and may apply inheritance in order to distribute interclass liability.
Decorator (Decorator). This template was formed for a dynamic connection of additional behavior to the object. With its help, the practice of creating subclasses receives a flexible alternative. This allows you to make the functionality wider.
Adapter (Adapter). It is necessary to organize the application of the functions of an object that cannot be modified through a special interface.
Compounder (Composite Pattern). Such a template is able to combine objects into a tree structure. This is useful for the presentation of the hierarchy from private to the whole. Thus, Composite Pattern gives customers the opportunity to turn to individual objects and groups of objects in the same way.
Deputy (Proxy). It provides an object that controls access to another object, while intercepting all the challenges. In other words, he acts as a container facade. It helps to hide the complexity of the system. The principle of operation is quite simple: all possible external challenges are reduced to the same object that transfers these calls to the corresponding objects of the system.
Manager (Flyweight, “lightweight (element)”). In the process of applying this pattern, the object represents itself as a unique copy in different parts of the program, however, in fact, this is not so.
Such patterns determine the algorithms and methods of implementing the interaction of any objects and classes. They reveal the general patterns of relations between objects that implement these templates. The use of behavioral patterns allows you to reduce the level of connectedness of the system and simplify the interaction between objects. This allows you to make a software product more flexible.
Iterator (Iterator). This is an interface that gives access to the elements of the collection (array or container), as well as navigation on them. Depending on the specific system, the iterators have different names. If we talk about management systems, then these are cursors.
Interpreter (Interpreter). He solves one very famous but constantly changing task. Alternative name – Little (Small) Language.
Chain of responsibilities. Such a template is needed to organize levels of responsibility in the system.
Keeper (Memento). With its help, you can consolidate and preserve the internal state of the object without impaired encapsulation. This is necessary so that in the future it is possible to restore it in this very state.
Team (Command). It represents the action and is used within the framework of object-oriented programming. The object of the team contains both the action itself and its parameters.
Mediator (mediator). This design pattern allows you to ensure the interaction of several objects. In the process of this, weak contact is created and objects get rid of the need for obvious links to each other.
Condition (stat). It is used in situations when, in the process of execution of the program, the object must change its behavior, depending on the state in which it is located.
Observer (Observer). It is also called “subordinates”. It forms a special mechanism in a class that makes it possible to receive notifications from the rest of the objects. The warning contains information about the change in their condition. Thus, the object is monitored.
Visitor (Visitor). Is responsible for the description of the operation, which is performed above the objects of other classes. If you make changes to Visitor, then you will not have to adjust the service classes.
Strategy (Strategy). This template is necessary in order to determine the families of algorithms and encapsulation of each of them. In addition, this pattern allows for their interchangeability. Thanks to this, it becomes possible to select the algorithm by determining the corresponding class. Using Strategy, you can change the algorithm used, regardless of the client objects using it.
Template Method). Determines the “foundation” of the algorithm and gives the heirs the opportunity to redefine certain steps of the algorithm, leaving its overall structure untouched.