The macro-control and micro-refinement of the six principles of "design pattern"

Source: Internet
Author: User

A day ago, I finally finished the second pass of the design pattern. In these two times, I learned a lot of knowledge. Before looking at OoTV design competition, always mentioned the principle of object-oriented design, which makes me unclear so, until after reading the whole book, only to know that the book has its own gold house. This article mainly writes about the six principles of object-oriented design.



According to this, we can easily conclude that object-oriented design is characterized by high cohesion, low coupling as the core of design, abstraction as the foundation, encapsulation, inheritance and polymorphism. Based on the principle, foundation and characteristics of object-oriented, we summarize its six principles. Through these six principles, we can also evolve a variety of design patterns. Here's my understanding of the six principles.


Dependency reversal

is an object-oriented flag! In which language to write the program is not important, it is important that the dependencies in the program are terminated in the abstract class or interface, which is object-oriented design.

Defined

1, high-level modules should not rely on low-layer modules, two should be dependent on the abstract

2, the abstract should not rely on the details, the details should be dependent on abstract


Single Responsibility

If a class takes on too much responsibility, it is tantamount to coupling those responsibilities together. A change in one's responsibilities may weaken or inhibit the ability of this class to perform other duties. So the real thing about software design is to discover responsibilities and separate those responsibilities from each other.

Defined

As far as a class is concerned, there should be only one cause for it to change


Dimitri

The premise of this principle is that in the structure design of a class, each class should minimize the access rights of its members. Its fundamental idea is to emphasize the weak coupling between classes. The weaker the coupling between the classes, the more beneficial the reuse, and a weakly coupled class is modified without causing a large ripple effect on the related classes.

Defined

1, if two classes do not have to communicate directly with each other, then these two classes should not have a direct interaction

2. If one of the classes needs to invoke a method of another class, the call can be forwarded through a third party.


synthesis /polymerization multiplexing

The advantage is that it helps keep each class encapsulated and focused on a single task. This reduces the strong coupling of inheritance and makes the program less likely to grow into an uncontrolled behemoth.

Defined

Use composition/aggregation as much as possible, and do not use class inheritance


the richter substitution

If the entity of a software is using a parent class, then it must apply to its subclasses, and the difference between the parent and subclass objects is not perceptible. More bluntly, it is in the software, the parent class is replaced by its subclasses, the behavior of the program has not changed.

Defined

Subtypes must be able to replace their parent type.

It is because of the principle of the substitution of the Richter scale that the following open closure becomes possible. The substitution of subclasses allows the modules of the parent class to be extended without modification.

Open closed

No matter how "closed" the module is, there will be some changes that cannot be closed to it. Since it is not possible to completely close, designers must first guess the most likely changes and then construct abstractions to isolate those changes.

The open closure principle is the focus of object-oriented design. Developers should abstract only those parts of the program that exhibit frequent changes.

Defined

In the face of updates to the requirements, changes to the program are made by adding new code, rather than changing the existing code.


Summary

The six major design principles are the evolution of object-oriented technology, which can be understood as an object-oriented inheritance. By combining these six principles, we have 23 more design patterns to understand, it will be more effective. This is the teacher's thinking, macro-control, micro-refinement. Miss Rice is really everywhere.

The macro-control and micro-refinement of the six principles of "design pattern"

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.