Object-Oriented Design Principles

Source: Internet
Author: User

Labels: design principles, class objects, resulting in design relationships, with extended and transparent modifications

1. Single Responsibility Principle
Definition:
An object should only contain a single responsibility, and this responsibility is fully encapsulated in a class.
The single responsibility principle is the guiding principle for achieving high cohesion and low coupling, which is the simplest but most difficult to use. Designers need to discover and separate different responsibilities of the class.

2. Open and Close principles
Definition:
The software entity shall be open to extensions and closed to modifications.
The software entity should be extended without modifying the original code.

3. Lee's replacement principle
Definition:
All objects that reference the base class must be transparently used.
The Rys replacement principle indicates that, in the software, replacing a base class object with its subclass object will not generate any errors or exceptions, but in turn will not be true.
When using the lean replacement principle, the parent class should be designed as an abstract class or interface, so that the subclass inherits the parent class or implements the parent class interface, and implements the methods declared in the parent class.

4. Dependency reversal Principle
Definition:
High-level modules should not depend on underlying modules. They should all rely on abstraction. Abstraction should not depend on details, but on abstraction.
Dependency reversal principle requirements: programming interfaces rather than implementing programming.

5. Interface isolation principles
Definition:
The client should not rely on interfaces that it does not need.
When using the interface isolation principle, you must control the granularity of the interface. The interface cannot be too small. If it is too small, the interface in the system may flood, which is not conducive to maintenance. The interface cannot be too large, too many interfaces violate the interface isolation principle, which is less flexible and inconvenient to use.

6. Principles of merging and reuse
Definition:
Object combination is preferred, rather than inheritance for reuse.
Generally, if the relationship between two classes is "has-a", combination or aggregation should be used. If the relationship is "is-a", inheritance can be used.

7. The dimit rule-also known as the minimum knowledge Principle
Definition:
Each software organization has only the minimum knowledge of other units and is limited to software units closely related to the same unit.

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.