Understanding of design Patterns

Source: Internet
Author: User

Design patterns are a set of reusable, most known, categorized purposes, code design experience Summary. Design patterns are used in order to reuse code, make code easier for others to understand, and ensure code reliability.

Six principles of design patterns

1. Opening and closing principle

Open for extensions, close for modifications.

2. The principle of substitution on the Richter scale

The principle of substitution on the Richter scale is one of the basic principles of object oriented design. The Richter substitution principle says that where any base class can appear, subclasses must be able to appear. The LSP is the cornerstone of inheritance reuse, and the base class can be reused only if the derived class is able to replace the base class and the functionality of the Software Unit is not affected, and the derived class can also add new behavior on the base class. The principle of substitution of the Richter scale is complementary to the principle of closure. The key step of realizing the opening and closing principle is abstraction, and the inheritance relation of the base class and subclass is the concrete realization of abstraction, so the principle of substitution of the Richter scale is the specification of the concrete steps to realize abstraction.

3. reliance on reversal principle

This principle is the basis of the open-close principle, the specific content: for the interface programming, dependent on the abstract and not dependent on the specific.

4. interface Isolation principle

This principle means that using multiple isolated interfaces is better than using a single interface. It also has another meaning: to reduce the degree of coupling between classes. Thus, in fact, the design pattern is from the large software architecture, easy to upgrade and maintain the software design ideas, it emphasizes the reduction of dependence, reduce coupling.

5, Dimitri Law, also known as least know the principle

The least known principle is that an entity should interact with other entities as little as possible, making the system function modules relatively independent.

6. principle of synthetic reuse

The synthetic reuse principle refers to the use of synthetic/aggregated methods rather than inheritance.

Common Design Patterns:

Factory mode: Creates a pattern that provides the best way to create an object. Factory mode is the most commonly used design pattern in PHP project development, and is typically used in conjunction with a singleton pattern to load classes in a PHP class library.

Singleton mode: Create pattern, which requires that a class has only one instance, and instantiates it itself and provides this instance to the entire system.

Abstract Factory mode: Create-mode,

Builder mode: Create-mode,

Prototype mode: Create-mode,

Interpreter mode, observer mode, policy mode, iterator mode, command mode, iterator mode, mediator mode

More design patterns are introduced, but not fully understood at the moment. Left behind to be perfected.

The principle and usage of various design patterns can be understood first by reference to design patterns.

Understanding of design Patterns

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.