"Reading" one, the six principles of object-oriented

Source: Internet
Author: User

I. Single RESPONSIBILITY

A class should be a set of highly correlated functions, the encapsulation of data

Two. Opening and closing principle

Objects (classes, modules, functions, etc.) in the software should be open for expansion and closed for modification.

Explanation: During the software life cycle, because of changes, upgrade maintenance and other reasons need to modify the old code, this time may break the old code has been tested, so should try to expand to modify the code, rather than by modifying the old code to achieve.

In fact, in reality, the modification of the original code and expansion of the code is at the same time.

Three. Richter replacement

All references to base classes must be able to transparently use objects of their subclasses

Explanation: Subclasses can appear as long as the parent class can appear, and there is no problem replacing them with subclasses

Summary: Abstract

Four. Dependency inversion

1. High-level modules are not dependent on low-layer modules, both rely on abstract

2. Abstraction does not depend on details

3. Detail dependent on abstraction

Explanation: Dependencies between modules occur through abstraction, and there is no direct dependency between the implementing classes, and their dependencies are generated through interfaces or abstract classes.

In fact, it can be understood as interface-oriented programming, or abstract programming

Five. Interface Isolation principle

Make the client dependent on the interface as small as possible

"Reading" one, the six principles of object-oriented

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.