Six design principles of design pattern

Source: Internet
Author: User

1, single duty principle: For a class, there should be only one cause of its change;

2, the Richter substitution principle: Subclasses must be able to replace the parent type with them;

3, open-closed principle: The program's entity objects (modules, classes, functions, etc.) should be extensible, but should not be able to modify;

1), two features of the open closure principle:

A), which is open for expansion;

b), for the modification is closed;

2) to realize the core idea of open-closed:

Face abstract programming, rather than specific programming.

4, relies on the reversal principle: The program's high-level module should not rely on the lower layer module, but both should depend on the abstraction, the abstraction should not depend on the concrete detail, but the detail should depend on the abstraction;

The meaning of the expression is that object-oriented should be programmed for the interface, not for implementation;

5, synthesis/aggregation reuse principle: Try not to use class inheritance, and use composition/aggregation as much as possible;

6, Dimitri rule: if there is no direct communication between the two classes, these two classes should not have a direct interaction. Day over one of the classes requires invoking a method in another class, which can be forwarded by a third party;

Dimitri: Emphasizing the need to implement loose coupling as much as possible between classes. The weaker the coupling between classes, the more beneficial it is to use multiplexing, where a weakly coupled class is modified without affecting the related classes, which in turn can cause a lot of trouble.

?

Six design principles of design pattern

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.