Software Design Principles

Source: Internet
Author: User

A few days ago, I saw a book "You must know. NET" from my friend and learned that this book was written by a high hand in our blog. I have received this book urgently. I have read it in a week. I am totally immersed in this book and sometimes forget the time. I don't even know the problem. I took some notes on the essence. Some of them I will share with you. If you have the opportunity, you can sell the book.

GOF said: good design makes good works. However, in terms of software design, under the principle of specification, our software will be restructured better. The following is my summary:

Three fundamental object-oriented design principles

--- Programming for interfaces, rather than implementing Programming

--- Prioritize the use of object combinations, rather than class inheritance

--- Encapsulation changes

Several more specific design principles:

1, Single responsibility (SRP, Sign Responsible Principle)

Core idea: a class, preferably only one thing, should have only one reason for its change (High Cohesion, low coupling)

 

2. Open and Closed Principle (OCP, Open Closed Principle)

Core Idea: class modules should be extended but cannot be modified (open to extensions and closed to changes)

L open to expansion means that existing code can be expanded to meet new requirements when new requirements change.

L closed changes mean that the class can complete its work independently once it is completed, without modifying the class.

 

3And Liskov replacement principle (LSP)

Core Idea: subclasses must be able to replace their base classes.

 

4, Dependency Inversion Principle (DIP, Dependency Inversion Principle)

Core Idea: dependent on abstraction.

L high-level modules should not depend on underlying modules, both of which should depend on abstraction.

L abstraction should not depend on implementation details, but on abstraction.

 

5, Interface isolation Principle (ISP, Interface Segregation Principle)

Core Idea: use multiple small and dedicated interfaces instead of large interfaces.

L interfaces should be cohesive and avoid "Fat interfaces ".

L The dependency of one class on the other class should be built on the smallest interface. Do not force the dependency on unused methods. This is an interface pollution.

 

6, Synthesis "aggregation Reuse Principle (CARP, Composite/Aggregate Reuse Principle)

Core Idea: Existing objects in the new object should be members of the object, so as to interact with other software entities as little as possible by operating these objects.

The rules are commonly used in the design 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.