Java and mode note (4) Dependency reversal Principle

Source: Internet
Author: User

☆The principle of dependency inversion depends on abstraction rather than specific implementation.

8.3 dependency reversal Principle

☆Three Coupling Relationships
① Zero coupling relationship. If there is no coupling relationship between the two classes, it is called zero coupling;
② Specific coupling occurs between two specific classes, caused by direct reference of another specific class by one class.
③ Abstract Coupling Relationships: Abstract coupling relationships occur between a specific class and an abstract class. There is maximum flexibility between two classes that must have a relationship.

☆Another statement of the dependency reversal principle is:
Do not program the interface (program to an interface, not an implementation) [gof95]. Similarly, when dealing with Coupling Relationships between classes, try to use abstract coupling forms.
A and B on the left are specific dependencies. After reconstruction, it becomes abstract dependency, as shown in the right figure:

☆The lean replacement principle is the basis of the dependency reversal principle.

☆The factory model, template model, and iteration submodel are the embodiment of the dependency reversal principle.

8.5 Java's support for abstract types
☆In design, the commonly used abstraction method is: first abstract something logically fixed, define an interface, and then define an abstract class to implement this interface, abstract classes implemented by this interface by default should implement most of the publicCodeThe specific class is generally derived from this abstract class.
Examples of containers in Java are as follows:

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.