Home > Common Problem > An explanation of the basic concepts of software design patterns

An explanation of the basic concepts of software design patterns

little bottle
Release: 2019-04-18 17:14:37
forward
2766 people have browsed it

Design patterns refer to solutions that developers summarize for problems they encounter repeatedly during software development. This article mainly introduces design patterns. Friends who are interested can take a look.

DesignPatternsPrinciple【Design Pattern Principle】

Six Principles of Design Pattern

  • Open and Closed Principle: A software entity such as a class , modules and functions should be open for extension and closed for modification.

  • Richter Substitution Principle: All places that reference a base class must be able to transparently use objects of its subclasses.

  • Dependency Inversion Principle: High-level modules should not depend on low-level modules, both should depend on their abstractions; abstractions should not depend on details; details should depend on abstractions.

  • Single Responsibility Principle: Do not have more than one reason for a class change. In layman's terms, a class is only responsible for one responsibility.

  • Interface isolation principle: The client should not rely on interfaces it does not need; the dependence of one class on another class should be based on the smallest interface.

  • Demeter's Law: An object should keep the least knowledge about other objects

Design pattern

Abstract Factory (Abstract Factory Pattern) : Provides an interface for creating a series of related or interdependent objects without specifying their specific classes.

Adapter (Adapter pattern): Convert the interface of a class into another interface that the customer wants. The Adapter pattern enables classes that would otherwise not work together due to incompatible interfaces to work together.

Bridge (Bridge Mode) : Separate the abstract part from its implementation part so that they can change independently.

Builder (Builder Pattern): Separate the construction of a complex object from its representation, so that the same construction process can create different representations.

Chain of Responsibility (Chain of Responsibility Mode): In order to decouple the sender and receiver of the request so that multiple objects have the opportunity to process the request. These objects are connected into a chain and the request is passed along the chain until an object handles it.

Command (command mode): Encapsulates a request as an object, allowing you to parameterize clients with different requests; queue requests or record request logs, and support optional Canceled operation.

Composite (composite mode): Combine objects into a tree structure to represent a "part-whole" hierarchy. Composite enables customers to use single objects and composite objects consistently.

Decorator (Decorator pattern): Dynamically add some additional responsibilities to an object. In terms of extended functionality, the Decorator pattern is more flexible than the subclassing method.

Facade (facade mode): Provides a consistent interface for a set of interfaces of a subsystem. The Facade mode defines a high-level interface that makes the subsystem easier to use.

Factory Method (Factory Method Pattern): Define an interface for creating objects and let subclasses decide which class to instantiate. Factory Method defers instantiation of a class to its subclasses.

Flyweight (flyweight mode): Use sharing technology to effectively support a large number of fine-grained objects.

Interpreter (interpreter mode) : Given a language, define a representation of its grammar, and define an interpreter that uses the representation to interpret sentences in the language .

Iterator (Iterator pattern): Provides a method to sequentially access each element in an aggregate object without exposing the internal representation of the object.

Mediator (Mediator Pattern): Use a mediator object to encapsulate a series of object interactions. Mediators remove the need for objects to explicitly reference each other, so they are loosely coupled and can independently change their interactions.

Memento (memo mode): Capture the internal state of an object and save this state outside the object without destroying encapsulation. This allows you to restore the object to its saved state later.

Observer (Observer Pattern): Define a one-to-many dependency relationship between objects, so that when the state of an object changes, all objects that depend on it are notified and automatically refresh.

Prototype (prototype mode): Use a prototype instance to specify the type of object to be created, and create a new object by copying this prototype.

Proxy (proxy mode): Provides a proxy for other objects to control access to this object.

Simple Factory (simple factory mode): Return instances of different classes according to different parameters.

Sigleton (single case mode) : Ensure that a class has only one instance and provide a global access point to access it.

State (State Mode) : Allows an object to change its behavior when its internal state changes. The object looks as if the class it belongs to has been modified.

Strategy (Strategy Mode): Define a series of algorithms, encapsulate them one by one, and make them interchangeable. This mode allows the algorithm to change independently of the user using it.

Template Method (Template Method Pattern) : Define the skeleton of an algorithm in an operation, while deferring some steps to subclasses. Template Method allows subclasses to redefine specific steps of an algorithm without changing the structure of the algorithm.

Visitor (visitor mode): Represents an operation that acts on each element in an object structure. It allows you to define new operations that act on each element without changing its class.

The relationship between design patterns

## UML class diagram illustration

Because UML will be used to explain the pattern structure in detail later, but here is a simple diagram.

If you want to know more related knowledge, please pay attention to

PHP Chinese website for more news!

The above is the detailed content of An explanation of the basic concepts of software design patterns. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template