Design Pattern Summary: One abstraction, two rules, three features, four principles and five relationships

Source: Internet
Author: User

The second learning of the design pattern is now a systematic summary of the design pattern.

Four Layers of Design Pattern learning:

The first layer is to understand each mode and understand what each mode is used.

The second layer implements code for each design mode.

Layer 3. Know the mode in which to use.

The fourth layer. design the model based on your own problems.

After this month's design model study, we have now passed the first layer. We have just finished the second layer. Now we have some contact with the third layer, but we still have a lot of knowledge to understand. further understanding is required. it took a week to read this book about the big talk design model. I can also feel the profound intention of the teacher's arrangement. although computers have become our primary means of learning, the most basic way of reading is not to let go. at the same time, reading books can bring you another feeling of freshness. through studying and thinking about the design model, I found that the whole book is about the following five contents.

1. abstraction 2. Rule 3 features 4 Principles 5 relationships

I. Abstraction

Abstract is to extract common and essential features from numerous things and discard non-essential features. Abstract is mainly used to reduce complexity and obtain simple concepts, so that people can control their processes to understand many specific objects. Abstract concepts throughout the big talk design model. is the basis of other concepts. the class itself is the abstraction of objects, while the abstract class and interface are the abstraction. understanding abstract concepts is a foundation for learning the big talk design model and a foundation for Learning Object-oriented ideas.

Rule 2:

1 dimit Law

The dimit rule is also called the minimum knowledge principle. The specific content is that if two classes do not need to communicate with each other directly, they should not directly interact with each other. if one class needs to call a method of another class, it can forward the call through a third party. in the big talk design model, the intermediary model is exquisite and reflects the dimit law.

2 interface isolation rules

The interface isolation rule is the same with the two concepts. One is the Demeter rule, and the other is the Dependency inversion principle. The main content of the interface isolation rule is: to create a single interface, do not create a bloated interface.

Three features:

1 Encapsulation

Encapsulation is to combine abstract data with behaviors (or functions) to form an organic whole, that is, to organically combine data with the source code of operational data, form a "class", where data and functions are members of the class. The purpose of encapsulation is to enhance security and simplify programming. We do not need to know the specific implementation details, but only use the class members through external interfaces and specific access permissions. A simple understanding of encapsulation is that a class is encapsulation.

2 Inheritance

The process of deriving a new class from an old class

3 polymorphism

The interface is implemented in a variety of ways, that is, polymorphism.

Four principles:

1. Single Function Principle

The single functional principle refers to a class, which should have only one reason for its change. this helps adapt to changes in requirements, so that programs can improve maintainability, reusability, and scalability. make the program more flexible. therefore, when programming, do more thinking on the separation of duties of classes to achieve a single responsibility. such code and programs have vitality.

2. Open and closed principles

The principle of openness and closure is that software entities (classes, modules, functions, etc.) should be extensible, but cannot be modified. that is, it is open to extensions and closed to modifications. you can extend a class, but you cannot modify a class. Otherwise, it violates the open/closed principle. the principle of opening/closing tells us that we should try to make this class good enough during programming. After writing it, we cannot modify it. How can we meet new requirements, instead of modifying the original class. the open and closed principle is also the core of object-oriented design.

3 dependency reversal Principle

For interface programming, do not implement programming. the high-level module should not depend on the underlying module, both of which should depend on abstraction. abstraction should not depend on details. Details should depend on abstraction. dependency inversion is a sign of object-oriented design. If all dependencies in a program are terminated by abstract classes or interfaces, object-oriented design is used, and reproduction is procedural design.

4. Li's replacement principle

Child types must be able to replace their parent classes. this principle makes inheritance reuse possible. Only when the child class can replace the parent class and the functions of the software unit are not affected can the parent class be reused, subclass can add new functions based on the parent class.

Five relationships:

The five relationships are dependency, Association (aggregation, combination), generalization, and implementation. Here we will not go into detail about these five relationships.

I think the above five elements are the fundamental and essential elements of the design model. All kinds of models are changed based on these principles and relationships. I think the ultimate goal of learning the design model is to learn the idea of the design model.

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.