Serialization: Object-oriented sunflower collection: thoughts, skills, and practices (36)-How to Use design principles?

Source: Internet
Author: User

Labels: Object-oriented Design Principles

After the previous in-depth explanation, we have basically made it clear about the solid principle. However, if you want to skillfully apply the solid principle, it is not enough to know what the solid is, we also need to know when and when the solid principle is applied (when or where ).

 

Fortunately, the five independence principles of the solid principle are essentially independent in actual applications, it is not necessary to select an optimal principle from the optional principles at the same time somewhere, which greatly reduces the difficulty of applying the solid principle.

 

The solid principle is applicable to the following scenarios:

  • SRP principle: used for Class Design

When we come up with a class or design a class prototype, use the SRP principle to check whether the class design meets the SRP requirements.

 

  • OCP principle: General Guiding Ideology

The OCP principle is a general guiding ideology. In the object-oriented design, if it can comply with the LSP/ISP/DIP principle, it can generally comply with the OCP principle.

In addition to object-oriented software design, OCP can also be used to guide system architecture design. For example, common CORBA and COM protocols can be considered as the specific application and implementation of the OCP principle.

 

  • LSP principle: used to guide the design of class inheritance

When we design the inheritance relationship between classes, we use the LSP principle to determine whether the inheritance relationship meets the LSP requirements.

 

  • ISP principle: used to guide Interface Design

The ISP principle can be considered as a variant of the SRP principle, which is essentially the same as the SRP principle. SRP is used to guide the design of classes, while ISP is used to guide the design of interfaces.

 

  • Dip principle: used to guide the design of class dependency

When designing the dependency between classes, we can use the dip principle to determine whether the dependency complies with the dip principle.

Dip principles and LSP principles complement each other: dip principles are used to guide the abstraction of interfaces or abstract classes, while LSP principles guide the derivation of New subclasses from interfaces or abstract classes.

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.