Java & Mode

Source: Internet
Author: User

Abstract and inheritance relationships allow reuse of concepts and definitions; polymorphism allows reuse of implementations and applications;

 

The principle of open-closed principle OCP is that a software entity should be open to extensions and closed to modifications.

Principle of encapsulation of variation (1) a variability is not mixed with another one (2) a variability should not be dispersedCode.

Liskov substitution principle: any base class can appear.

Dependence inversion: dependent on abstraction and implementation.

Combination/aggregation Reuse Principle (composite/aggregate Reuse Principle): use combination/aggregation as much as possible, rather than inheritance relationships.

Dimit Law: A software entity should have as few relationships as possible with other software entities.

Interface segregation principle: Provides the client with as few independent interfaces as possible, rather than a large total interface.

 

When does Coad Principle Use inheritance reuse?

(1) subclass is a special category of superclass. It is not a role of a superclass. It is distinguished by is-a and has-.

(2) Extend the super class responsibilities of sub-classes, rather than replacing them.

(3) There will never be a situation where you need to replace a subclass with a subclass of another class.

(4) inheritance is used only when the classification is meaningful. do not inherit from the tool class.

 

Several factory models solve the dependency reversal principle during object creation.

 

Abstract class purpose:

(1) If a specific class is not used for inheritance, try to inherit from an abstract class.

(2) abstract classes have as much code and as little data as possible

 

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.