Design Model-six principles application scenarios Popular edition (1)

Source: Internet
Author: User

1> single Responsibility Principle

This is the most common design principle of our design program. For example, user information, attributes and behaviors, basic information belongs to the attribute class, and execution belongs to the behavior class or interface, in actual projects, most of them can only be used in this place.

2> Lee's replacement principle

Avoid the negative reconstruction effects of inheritance relationships as much as possible

Notes:

2.1 when calling other classes, try to use interfaces or parent classes of other classes as much as possible, which is also our regular habit.

2.2 If the Child class cannot fully implement the parent class method or the parent class method has a ambiguity in the Child class, disconnect the Parent-Child inheritance relationship and switch to dependency, aggregation, and combination associations, in general, when the sub-class and parent class attributes or actions may have elements and methods that do not have an inheritance relationship, create a parent class to do specific things, the newly created parent class must have a dependency or other associations with the original parent class, which is often used by spring or hibernate in the framework.

3> Dependency inversion principle

The straightforward point of dependency inversion is to make the business interface as much as possible and adopt interface-based programming to reduce the maintenance and expansion costs. It is a good principle method for parallel development, interface-based programming is a common practice in large-scale distributed systems.

4> interface isolation principle

Based on the actual project, we try to separate as many business-defined interfaces as possible to facilitate single business customization and avoid the loss of system performance caused by design defects.

5> Demeter's Law

Make business code cohesion as much as possible to reduce external exposure.

6> Open and Close principles

Rewrite the parent class method as much as possible without modifying the parent class.

Design Model-six principles application scenarios Popular edition (1)

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.