Design Pattern note (1)-opening part (article index)

Source: Internet
Author: User
Document directory
  • Concept
  • Design Pattern and object-oriented
  • From design principles to design patterns
  • Several Design Principles
  • Classification of design patterns
Concept

The design pattern describes a general solution to a type of common problems in the software design process.

The object-oriented design pattern describes the common organizational relationships between classes and communication objects in specific scenarios during the object-oriented design process.

Design Pattern and object-oriented

The object-oriented design model solves the Organizational Relationship between classes and communication objects. Including their roles, responsibilities, and collaboration methods.

The object-oriented design mode is "Good object-oriented design". The so-called "Good object-oriented design" is the design that can meet the requirement of "improving reuse due to changes ".

Object-Oriented Design Patterns Describe software design, so they are independent of programming languages, but the ultimate implementation of object-oriented design patterns still needs to be expressed in object-oriented programming languages.

Unlike algorithm techniques, the object-oriented design pattern can be copied and used. It is based on an empirical understanding of the "facial image object.

From design principles to design patterns

Programming for interfaces, rather than implementing programming-customers do not need to know the specific types of objects used, but only need to know that the object has the interface the customer expects.

Object combination is preferred, rather than class inheritance-class inheritance is usually "white box reuse", and object combination is usually "black box reuse ". Inheritance damages encapsulation to some extent, and the Child class parent class has a high Coupling Degree. The combination-oriented object only requires that the combined object has a well-defined interface, and the coupling degree is low.

Encapsulation change point-use encapsulation to create a boundary between objects, so that the designer can modify the boundary on one side without adversely affecting the other side, to achieve loose coupling between layers.

Use refactoring to get the pattern-the application of the design pattern should not be preemptible. First, the use of the design pattern is the greatest useless to the design pattern. There is no one-step design model.

Several Design Principles

In the use of the design pattern, the following principles are carried out all the time. Therefore, understanding these design principles is of great help for learning and understanding the design pattern.

1. Single original responsibility (SRP): A class should have only one reason for its change.

2. Open and closed principle (OCP): class modules should be extensible, but cannot be modified (multiple extensions are open and closed for modification)

3 Liskov replacement principle (LSP): subclass must be able to replace their base class

4. Dependency inversion principle (DIP): the high-level module should not depend on the underlying module. Both should depend on abstraction. abstraction should not depend on implementation details. Implementation Details should depend on abstraction.

5. Interface isolation principle (ISP): customer programs should not be forced to rely on methods they do not need.

The above is just a simple definition. There are a lot of details about these principles on the Internet.

The following is a brief introduction of my own understanding of the design model, which has been in touch for a long time. However, there are only a few actually used in the project, there are many books on design patterns on the market, some of which are vivid examples and easy to understand. However, design patterns are not simple demos, I personally feel that there is a long way to go from being familiar with those simple demos to being able to use them flexibly in projects. We need to write more, think more, and summarize more. The reason for using the design pattern is that when changes come, we can solve the problem more conveniently and quickly, and facilitate future maintenance. If there is no change in demand, you can implement the function in a simple and direct way, but the demand is always changeable. The design pattern we usually talk about refers to the object-oriented design pattern, so learning the Object-Oriented Knowledge is the prerequisite for learning the object-oriented design pattern. Recently, I spoke about the Design Pattern webcast lectures several years ago. I felt that I had gained a lot and made some notes for later use.

Classification of design patterns

Design Patterns are classified into three categories: creation, structure, and behavior.

Creation type

Singleton

Abstract Factory Mode

Builder Mode

Factory Method mode

Prototype

Structural

Adapter Mode

Bridge Mode

Composite Combination Mode

Decorator decoration Mode

Facade appearance Mode

Flyweight meta Mode

Proxy Mode

Behavior Type

TemplateMethod template method mode

Command mode

Interpreter Mode

Mediator intermediary Mode

Iterator Mode

Observer Mode

Chain Of Responsibility Chain model

Memento memorandum Mode

State Mode

Strategy Mode

Visitor Mode

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.