Lecture
A design pattern or pattern in software design is a repeatable architectural design that represents the solution to a design problem within a context that often arises.
Typically, a pattern is not a complete pattern that can be directly converted to code; This is just an example of solving a problem that can be used in various situations. Object-oriented patterns show relationships and interactions between classes or objects, without determining which end classes or application objects will be used.
"Low-level" patterns that take into account the specifics of a particular programming language are called idioms. These are good design solutions, specific to a particular language or software platform, and therefore not universal.
At the highest level, there are architectural patterns , they cover the architecture of the entire software system.
Algorithms are inherently also templates, not calculations, but calculations, since they solve computational problems.
In the 1970s, architect Christopher Alexander created a set of design patterns. In the field of architecture, this idea did not receive such a development as later in the field of software development.
In 1987, Kent Beck and Ward Cunningham took Alexander's ideas and developed templates for developing software for developing graphical shells in the Smalltalk language.
In 1988, Erich Gamma began writing a doctoral thesis at the University of Zurich on the general portability of this methodology for program development.
In 1989-1991, James Coplin (James Coplien) worked on the development of idioms for programming in C ++ and published in 1991 the book Advanced C ++ Idioms.
In the same year, Erich Gamma finished his doctoral thesis and moved to the USA, where in collaboration with Richard Helm, Ralph Johnson and John Vlissides publishes the book Design Patterns - Elements of Reusable Object-Oriented Software. This book describes 23 design patterns. Also, the team of authors of this book is known to the public under the name "Gang of Four" (English Gang of Four , often reduced to GoF ). This book was the reason for the growing popularity of design patterns.
In comparison with fully independent design, templates have several advantages. The main advantage of using templates is to reduce the complexity of the development at the expense of ready-made abstractions to solve a whole class of problems. The template gives the solution its name, which facilitates communication between developers, allowing you to refer to known templates. Thus, at the expense of templates, unification of the details of the solutions is made: modules, project elements - the number of errors is reduced. The use of templates is conceptually similar to using ready-made code libraries. Properly formulated design pattern allows finding a successful solution, use it again and again. A set of templates helps the developer to choose the most suitable design option. [1]
Although a slight change in the code for a known pattern can simplify the understanding of the code, according to Steve McConnell, two difficulties can be associated with the use of patterns. First, blindly following a certain pattern can lead to complication of the program. Secondly, the developer may be tempted to try some pattern in the case without any particular reason. [2]
Many design patterns in object-oriented design can be viewed as idiomatic reproduction of elements of functional languages [3]. Peter Norvig claims that 16 of the 23 templates described in the book “Gangs of Four” are much easier to implement in Lisp or Dylan than in C ++, or they are invisible [4]. Paul Graham considers the idea of design patterns itself to be an anti-pattern, a signal that the system does not have a sufficient level of abstraction, and it needs careful processing [5]. It is easy to see that the definition of the template itself as “a ready-made solution, but not a direct access to the library ” in essence means a refusal to reuse in favor of duplication. This, obviously, can be inevitable for complex systems when using languages that do not support combinators and type polymorphism, and this can in principle be excluded in languages that have the property of [en] (although not necessarily efficiently), since any pattern can be implemented as executable code [6].
Title | original name | Description | Described in Design Patterns |
---|---|---|---|
Basic Patterns (Fundamental) | |||
Delegation Template | Delegation pattern | The object outwardly expresses some behavior, but in reality transfers responsibility for the execution of this behavior to the related object. | N / A |
Functional Design Template | Functional design | Ensures that each module of a computer program has only one duty and performs it with a minimum of side effects to other parts of the program. | N / A |
Immutable interface | Immmtable interface | Creating an immutable object. | N / A |
Interface | Interface | A common method for structuring computer programs to make them easier to understand. | N / A |
Interface marker | Marker interface | As an attribute (as an entity tag), the presence or absence of a marker interface implementation is applied. In modern programming languages, attributes or annotations may be used instead. | N / A |
Property Container | Property container | Allows you to add additional properties for a class to a container (inside a class), instead of extending the class with new properties. | N / A |
Event channel | Event channel | Extends the Publish / Subscribe template by creating a centralized channel for events. Uses the proxy for the subscription and the proxy for posting a channel event. The representative exists separately from the actual publisher or subscriber. A subscriber can receive published events from more than one object, even if it is registered on only one channel. | N / A |
Creational patterns are design patterns that abstract the instantiation process. They allow you to make the system independent of the way you create, compose and present objects. The template that generates the classes uses inheritance to change the class to be instantiated, and the template that generates the objects delegates the instantiation to another object. | |||
Abstract Factory | Abstract factory | A class that provides an interface for creating system components. | Yes |
Builder | Builder | A class that represents an interface for creating a complex object. | Yes |
Factory Method | Factory method | Defines an interface for creating an object, but leaves the subclasses a decision on which class to instantiate. | Yes |
Delayed initialization | Lazy initialization | An object that was initialized during the first call to it. | Not |
Pool singles | Multiton | Ensures that the class has named object instances and provides a global access point to them. | Not |
Object pool | Object pool | A class that represents an interface for working with a set of objects initialized and ready to use. | Not |
Prototype | Prototype | Defines an interface for creating an object through cloning another object instead of creating through a constructor. | Yes |
Getting a resource is initializing | Resource acquisition is initialization (RAII) | Getting some resource is combined with initialization, and the release - with the destruction of the object. | Not |
Single mother | Singleton | A class that can only have one instance. | Yes |
Structural patterns (Structural) define various complex structures that modify the interface of already existing objects or its implementation, making it easier to develop and optimize the program. | |||
Adapter | Adapter / Wrapper | An object that provides interaction between two other objects, one of which uses and the other provides an interface incompatible with the first. | Yes |
Bridge | Bridge | A structure that allows you to change the call interface and the class implementation interface independently. | Yes |
Linker | Composite | An object that combines objects like itself. | Yes |
Decorator or Wrapper / Wrapper | Decorator | A class that extends the functionality of another class without using inheritance. | Yes |
Facade | Facade | An object that abstracts work with several classes, combining them into a coherent whole. | Yes |
Single entry point | Front controller | Provides a unified interface for interfaces in a subsystem. Front Controller defines a high-level interface that simplifies the use of the subsystem. | Not |
Adapted | Flyweight | This is an object that represents itself as a unique instance in different places of the program, but in fact is not one. | Yes |
Deputy | Proxy | An object that is an intermediary between two other objects, and which implements / restricts access to the object that is accessed through it. | Yes |
Behavioral patterns (Behavioral) define the interaction between objects, thus increasing its flexibility. | |||
Chain of responsibility | Chain of responsibility | Designed to organize in the system of levels of responsibility. | Yes |
Team, Action, Transaction | Command | Represents an action. The command object contains the action itself and its parameters. | Yes |
Interpreter | Interpreter | Solves a frequently occurring, but subject to change, task. | Yes |
Iterator, Cursor | Iterator | It is an object that allows to get sequential access to the elements of an aggregate object without using descriptions of each of the objects that make up the aggregation. | Yes |
Mediator | Mediator | Ensures the interaction of multiple objects, while forming a weak connection and eliminating the objects from having to explicitly refer to each other. | Yes |
Keeper, token | Memento | It allows not fixing the encapsulation and fixing and preserving the internal state of the object so that it can be restored later in this state. | Yes |
Null object | Null object | Prevents null pointers by providing a “default” object. | Not |
Observer, Dependents, Publish-Subscribe, Listener | Observer or Publish / subscribe | Defines a one-to-many dependency between objects in such a way that when a state of a single object changes, all dependent dependencies are notified of this event. | Yes |
Servant | Servant | Used to provide general functionality to a class group. | Not |
Specification | Specification | Serves to bind business logic. | Not |
State, Objects for States | State | It is used in cases when, during the execution of a program, an object must change its behavior depending on its state. | Yes |
Strategy | Strategy | Designed to define a family of algorithms, encapsulate each of them, and ensure their interchangeability. | Yes |
Template Method | Template method | It determines the basis of the algorithm and allows the heirs to override certain steps of the algorithm, without changing its structure as a whole. | Yes |
Visitor | Visitor | Describes an operation that is performed on objects of other classes. When changing the class Visitor there is no need to change the classes served. | Yes |
Simple policy | Simple policy | Not | |
Event listener | Not | ||
One time visitor | Single-serving visitor | Optimizes the implementation of the template visitor, which is initialized, once used, and then deleted. | Not |
Hierarchical visitor | Hierarchical visitor | Provides a way to bypass all the vertices of a hierarchical data structure (for example, a tree). | Not |
Concurrency - Concurrency
Concurrency patterns [edit | ]
Used for more efficient writing of multi-threaded programs, and provides ready-made solutions to synchronization problems.
Title | original name | Description |
---|---|---|
Active Object | Active object | Serves to separate the thread of the method from the thread in which it was called. Uses templates asynchronous method call and scheduler. |
Talking | Talking | Serves to perform an action on an object only when it is in the correct state. |
Binding properties | Combines several observers to ensure the synchronization of properties in various objects [7] | |
Message exchange | Messaging design pattern (MDP) | Allows components and applications to exchange information (messages). |
Double check lock | Double-checked locking | Designed to reduce the overhead associated with obtaining a lock. |
Event-based asynchronous | Address problems with the Asynchronous pattern that occur in programs with multiple threads. [8] | |
Secure suspension | Guarded suspension | It is used to block the execution of an action on an object only when it is in the correct state. |
Half-Sync / Half-Async | ||
Leaders / followers | ||
Lock | One thread locks a resource to prevent access or alter it by other threads. [9] | |
Monitor | Monitor object | An object intended for safe use by more than one stream. |
Reactor | Reactor | Designed for simultaneous transmission of requests to the service from one or more sources. |
Read write lock | Read-write lock | Allows multiple threads to simultaneously read information from a shared repository, but allowing only one thread to change it at the current time. |
Scheduler | Scheduler | Provides a mechanism for implementing a planning policy, but not dependent on any particular policy. |
Thread pool | Thread pool | Provides a pool of threads for processing jobs, usually represented as a queue. |
Thread-Specific Storage | Thread-specific storage | Serves to provide different global variables for different threads. |
Single threaded execution | Single thread execution | Interferes with the competitive challenge of the method, thereby prohibiting the parallel execution of this method. |
Cooperative pattern | Cooperative pattern | Provides a mechanism to safely stop execution threads using a common flag to signal the termination of a thread's operation. |
MVC
Enterprise t]
Other
Also today there are a number of other templates:
Comments
To leave a comment
Object oriented programming
Terms: Object oriented programming