Equivalence and Similar Relations in Java Inheritance

After the subclass inherits the superclass, the subclass has the same interface as the superclass, so the type of the subclass and the superclass is the same.
As a result, an object of the subclass can be replaced with an object of the parent class. At this time, it can be considered that the subclass and the superclass are an "equivalence" relationship.

However, when the subclass inherits the parent class and adds some new interfaces, although the subclass can still replace the parent class, the replacement is incomplete
because the new function cannot be accessed in the parent class, which is called a "similar" relationship .
As an example, let's consider the case of a refrigerator. Suppose our room is wired up with various controllers for cooling; that is, we already have the necessary "interfaces" to control cooling. Now let's say the machine breaks down and we replace it with a new type of air conditioner that can be used in both winter and summer. Hot and cold air conditioners are "similar" to refrigerators, but do more. Since our room only had equipment to control the cooling, they were limited to dealing with the cooling part of the new machine. The interface of the new machine has been extended, but the existing system does not know anything other than the original interface. 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324847996&siteId=291194637