Basic knowledge of design patterns

Source: Internet
Author: User

Introduction to Design Patterns    

Design Patterns are a set of reusable, most known, categorized purposes, code design experience Summary. Design patterns are used to reuse code, make code easier for others to understand, and ensure code reliability. There is no doubt that design patterns in others in the system are multi-win, design patterns so that code is truly engineering, design patterns are the cornerstone of software engineering, like a block of bricks and tiles in the building.

What is GOF (Gang of Four, all spell Gang of four)?

In 1994, four people, from Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, co-authored a book titled Design patterns-elements of REUSABLE object-oriented Software (Chinese translation: Design Patterns-Reusable object-oriented software elements) , the book mentions the concept of design patterns in software development for the first time.

The four authors collectively referred to GOF (Gang of Four, the All-spell Gang of all). The design patterns they propose are mainly based on the following object-oriented design principles.

    • Programming the interface rather than the implementation.

    • Use object combinations rather than inheritance.

Types of Design Patterns

According to the design pattern of the reference book   design patterns-elements of reusable object-oriented software (Chinese translation: Designing Patterns-Reusable object-oriented software elements)  , there are 23 design patterns in total. These patterns can be categorized into three main categories: the creation pattern (creational Patterns), the structural pattern (Structural Patterns), and the Behavioral pattern (behavioral Patterns). Of course, we'll also discuss another type of design pattern: the Java EE design pattern.

The relationships between design patterns are as follows:


Six principles of design patterns

1. Opening and closing principle (Open Close Principle)

The opening and closing principle means: open for expansion, close for modification . When the program needs to expand, can not modify the original code, to achieve a hot plug effect. In short, it is to make the program extensibility, easy to maintain and upgrade. To achieve this, we need to use interfaces and abstract classes, which we will refer to later in the specific design.

2. The principle of substitution on the Richter scale (Liskov Substitution Principle)

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. Dependence reversal principle (dependence inversion 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 (Interface segregation 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 (Demeter 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. Synthetic multiplexing principles (Composite reuse Principle)

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


Basic knowledge 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.