Object-oriented design principles and design principles

Source: Internet
Author: User

I. Design Principles
1. Dependency inversion principle (DIP)

High-level modules (stability) should not depend on low-level modules (changes), both of which should depend on abstraction.
Abstract (stable) should not depend on implementation details (changes), and implementation details should depend on abstraction.

2. Open and closed principle (OCP)

Class modules should be extensible, but cannot be modified; open to extensions and closed to changes

3 single responsibility principle (SRP)

A class should have only one reason for its change.

4 liskov replacement principle (LSP)

Subclass must be able to replace their base classes

5 interface isolation principle (ISP)

Customers should not be forcedProgramDepending on the methods they do not need.

2. Object-oriented Design Principles

1. Interface Programming, not implementation programming
The customer does not need to know the specific type of the used object, but only needs to know that the object has the interface that the customer expects.

2. Object combination is preferred, rather than class inheritance.
Class inheritance is usually "white box reuse", and the object combination is usually "black box reuse ". Inheritance damages encapsulation to some extent, and the Child class parent class has a high Coupling Degree. Object combination only requires that the combined object has a well-defined interface, and the coupling degree is low.

3. encapsulation changes
The encapsulation is used to create the demarcation layer between objects, so that the designer can modify the interface on one side of the demarcation layer without affecting the other side, so as to implement loose coupling between layers.

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.