Notes on design patterns

To your attention, I would like to offer notes that I left for myself when studying design patterns.
I want to immediately stipulate the point that you will not meet all the patterns in this article, and if this article seems interesting to you, I will continue.
Let's go!

The “Strategy” pattern defines a family of algorithms, encapsulates each of them and ensures their interchangeability. It allows you to modify the algorithms regardless of their use on the client side. Also, the “Strategy” pattern is used to implement different behaviors.

The Observer pattern defines a one-to-many relationship between objects in such a way that when a state of one object changes, it automatically notifies and updates all dependent objects.

The “Decorator” pattern dynamically gives an object new possibilities and is a flexible alternative to subclassing in the field of expanding functionality.

The Factory pattern encapsulates the details of creating a class. The factory method is responsible for creating objects and encapsulates this operation in a subclass. The Factory Method pattern defines the interface for creating an object, but allows subclasses to select the class of the instance to be created. Thus, the "Factory Method" delegates the operation of creating an instance of the object.

The Abstract Factory pattern provides an interface for creating families of interconnected or interdependent objects, without specifying their specific classes. The factory method is based on inheritance: the creation of objects is delegated to subclasses that implement the factory method for creating objects. An abstract factory is based on composition: the creation of objects is implemented in a method that is accessed through the factory interface. The task of the factory method is to move instance creation to subclasses. The task of the Abstract Factory is to create families of interconnected objects without depending on their specific classes.

The Loner pattern is aimed at creating unique objects that exist in one instance.

The “Command” pattern separates the party issuing the request from the object performing the operation. This pattern encapsulates the request in the form of an object, making it possible to parameterize client objects with other requests, queuing or registering requests, as well as support for canceling operations. In general, the “Command” pattern is used when it is necessary to separate the object issuing the requests from the objects that are able to fulfill these requests.

The “Adapter” pattern transforms the class interface to another interface that the client is designed for. The adapter provides class collaboration that is not possible under normal conditions due to interface incompatibility.

The Facade pattern provides a unified interface to the subsystem interface group

The Facade pattern not only simplifies the interface, but also provides logical isolation of the client from a subsystem consisting of many components. The façade is used for simplification, and the adapter is used to transform the interface to another form. This pattern prevents strong connections between the client and the subsystem.

The Pattern Method method sets the skeleton of the algorithm in the method, leaving the definition of the implementation of some steps to subclasses. Subclasses can override some parts of the algorithm without changing its structure.

Thank you all for your attention!

Also popular now: