Reading Notes 4 in Java and patterns-LSP and dip)

Source: Internet
Author: User

LSP: If O1 is an object of Type T1, T2. so that all objects defined by T1 can beProgramWhen P is replaced by O2 for all object O1, the behavior of program P does not change, so Type T2 is the child type of Type T1. In other words, if a software entity uses a base class, it must be used in its subclass, and it cannot detect the difference between a base class object and a subclass object.

The Rys replacement principle is the cornerstone of inheritance reuse. Only when the category class can replace the base class and the functions of the software unit are not affected will the base class be reused, and the category class can also add new behaviors based on the base class.

Dependency inversion principle (DIP): It depends on abstraction and not on specifics.

The traditional process system design method tends to make high-level modules depend on low-level modules, and the abstract layer depends on specific layers. The reversal principle is to reverse the dependency of such errors.

Three Coupling Relationships:

Zero coupling: If two classes have no coupling relationship, it is called zero coupling.

Specific coupling: the concrete coupling occurs between two (instantiated) classes and is caused by direct reference of one class to another.

Abstract coupling: Abstract coupling occurs between a specific class and an abstract class (or interface), so that two classes that must have a relationship have the maximum flexibility.

The dependency inversion principle requires the client to rely on abstract coupling.

Abstraction should not depend on details; details should depend on abstraction.

Do not implement programming for the interface.

When a variable is declared, the type is called the static type of the variable, or the obvious type. The actual type of the object referenced by the variable is called the actual type of the variable.

When a program needs to reference an object, it should use abstract types as the static type of variables as much as possible, which is the meaning of interface programming.

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.