Java and mode-interface isolation principle, combined aggregation and reuse, prompt rule, single Responsibility Principle

Source: Internet
Author: User

1. Interface isolation principle

1. It is better to use multiple interfaces than to use a single interface

2. rational division of roles: an interface represents a role

3. Custom Service: divide an interface into interfaces with different widths to correspond to different customers

4. interface contamination

1 An interface encapsulates too many methods, and the Division is unreasonable

2 combines tasks of different roles into one interface

 

 

Principle of combined aggregation Reuse

1. Try to use combination aggregation instead of inheritance.

2. the inheritance is static, and the combination of aggregation and reuse can be dynamically determined at runtime.

4. When one category is another: for example, men and women are human beings, while formal and temporary employees are employees.

5. When a class has some roles, such as students, managers, and drivers. People may have three roles at the same time, so they must use combination aggregation for reuse. It is static for inheritance. People can only be students, managers, or drivers. Once confirmed, they cannot change. This certainly does not match.

 

 

Tridimit's Law

1. Do not communicate with a software entity unless it must communicate with another software entity

 

 

Four single responsibilities

1. A class can only be changed in one place, and only one place can be changed in one hierarchy,

Do not mix two changes

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.