Principle of object-oriented thought design

Source: Internet
Author: User

Single principle of responsibility

In fact, developers often say, "high cohesion, low coupling"

In other words, each class should have only one responsibility, and only one function can be provided externally, and the cause of the class change should only be the same. In design mode, all design patterns follow the principle

Opening and closing principle

The core idea is: an object to expand open, to modify the close

In fact, the opening and closing principle means that changes to the class are made by adding code, not by modifying the existing code.

In other words, once the software developer writes out the code that can be run, it should not change it, but to ensure that it can continue to run, how can this be done? This requires abstraction and polymorphism, that is, to abstract the content that is likely to change, so that the abstract part is relatively stable, and the concrete implementation can be changed and extended

Lee's replacement principle:

The core idea: where any parent class appears, it can be substituted with its subclasses

In fact, it is said that the objects in the same inheritance system should have common behavioral characteristics.

Core injection principles:

Core idea: To rely on abstraction, do not rely on concrete implementation

In fact, in an application, all classes, if the goods depend on other classes, should rely on the abstract classes of those other classes, not the concrete classes of those other classes. In order to implement this principle, we are required to program at the time of programming for the abstract class or for the deduction, rather than for the specific implementation of the programming

Interface Separation principle:

Core idea: The program should not be forced to rely on methods that they do not need to use

In fact, it is said: an interface does not need to provide too much behavior, an interface should be provided only an external function, should not be all the operations are encapsulated in a connector

Dimitri Principle:

Core idea: An object should know as much as possible about other objects

In fact, it is said: reduce the coupling between the various objects, improve the maintainability of the system. Between the modules should only be programmed through the interface, regardless of the internal workings of the module, it can reduce the coupling of the Brother module to a minimum, promote the reuse of software

Principle of object-oriented thought 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.