Object-Oriented design principles

Source: Internet
Author: User

Object-Oriented design principles:

1. Single Duty principle (SRP): each class in the system should have only one responsibility.

Benefits: cohesion, low coupling.

2. Opening and closing principle (OCP): open for extension, closed for modification.

Benefits: Increased adaptability and flexibility, stability and continuity, reusability and maintainability.

3. The Richter Replacement principle (LSP): Wherever the parent class appears, it can be replaced with its subclasses without compromising performance.

Polymorphism is the implementation of the Richter scale substitution principle.

4. Dependency inversion principle (DIP): high-level modules should not rely on the underlying modules, both should rely on their abstraction; abstractions should not depend on detail, and detail should be dependent on abstraction.

Benefits: Improve the stability of the program, maintainability, Extensibility.

5. Interface Isolation principle (ISP): using multiple specialized interfaces is better than using a single total interface.

Benefit: Do not force new functionality to implement unnecessary methods.

6. Dimitri Principle (LOP): an object should have as little knowledge of other objects as possible. A class is called by a mediation class instead of directly calling another class.

Pros: Reduce coupling, disadvantage: Increase code complexity and reduce operational efficiency.

7. Combination/Aggregation multiplexing principle (CARP): prioritize the use of combination/aggregation to make the system more flexible, followed by inheritance, to achieve reuse.

Benefit: The combination multiplexing requires less dependency, the combination is dynamic during program run time, and the new object can dynamically reference the same object as the constituent object. Cons: Using a combination/combination will generate more objects that need to be managed.

 

Object-Oriented design principles

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.