The solid principle of Object-Oriented Design

Source: Internet
Author: User

Labels: C ++ solid principle object-oriented design ideas

The solid principle of Object-Oriented Design

SRP the single responsibility principle single Responsibility Principle

OCP the open closed principle Principle

LSP the liskov substitution principle's replacement principle

Dip the Dependency inversion principle

ISP the interface segregation principle interface separation principle

Single responsibility principle:

There is only one reason for modifying a class. In other words, let a class only take one type of responsibility. When this class needs to take responsibility for other types of responsibilities, it needs to be broken down.

Principle of opening and closing:

The software entity should be extensible and unchangeable. That is to say, it is open to extensions and closed to modifications. This principle is the most abstract and hard to understand among many object-oriented programming principles.

Lee's replacement principle:

When a subclass instance should be able to replace any of its superclasses, There Is A is-a relationship between them.

Dependency inversion principle:

1. High-level modules should not depend on low-level modules. Both of them should depend on abstraction.

2. abstraction should not depend on details, but on abstraction.

Interface separation principle:

Users cannot be forced to rely on interfaces they do not use. In other words, it is better to use multiple dedicated interfaces than to use a single total interface.

The main progress of object-oriented development is to encapsulate and hide data. Looking at objects from the outside is like a "black box". data and methods are hidden and invisible. When using an object, you do not need to know the specific implementation details of the object. You only need to access the object based on the external interface provided by the object.

Encapsulation: Put the data of an object together with the operations related to the data. Each object is independent of each other and does not interfere with each other. Only a small number of interfaces are left for external contact.

Encapsulation should have the following characteristics:

With a clear boundary, Private Members are encapsulated inside, and external access is not allowed to provide necessary interfaces.

The data and methods inside the object are protected by the Encapsulation Shell. Other objects cannot be used directly.

The solid principle of Object-Oriented Design

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.