📜 ⬆️ ⬇️

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 say that you will not meet all the patterns in this article, and if this article seems interesting to you, then I will continue.
Let's go!

The Strategy pattern defines a family of algorithms, encapsulates each of them, and ensures their interchangeability. It allows modifying 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 a single object changes, an automatic notification and updating of all dependent objects occurs.

The “Decorator” pattern dynamically gives the object new opportunities 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 an object creation interface, but allows subclasses to select the class of the instance being created. Thus, the “Factory Method” delegates the operation of creating an object instance.

The Abstract Factory pattern provides an interface for creating families of interrelated 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. The 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 the creation of the instance into subclasses. The task of the Abstract Factory is to create families of interrelated objects without depending on their specific classes.

The Singleton pattern is aimed at creating unique objects that exist in one copy.

The “Command” pattern separates the party issuing the request from the object performing the operation. This pattern encapsulates the request as 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 requests from objects that are able to fulfill these requests.

The “Adapter” pattern converts the class interface to another interface that the client is designed for. The adapter allows classes to work together that is impossible under normal conditions due to incompatibility of interfaces.

The “Facade” pattern provides a unified interface to a group of subsystem interfaces

The “Facade” pattern not only simplifies the interface, but also provides logical isolation of the client from a subsystem consisting of many components. The facade is used to simplify, and the adapter - to convert the interface to another form. This pattern prevents strong links between the client and the subsystem.

The Pattern Method pattern 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!

Source: https://habr.com/ru/post/130285/


All Articles