如何区分class inheritance和interface inheritance

It's also important to understand the difference between class inheritance and interface inheritance (or
subtyping). Class inheritance defines an object's implementation in terms of another object's implementation.
In short, it's a mechanism for code and representation sharing. In contrast, interface inheritance (or
subtyping) describes when an object can be used in place of another.

Many of the design patterns depend on this distinction. For example, objects in a Chain of Responsibility
(223) must have a common type, but usually they don't share a common implementation. In the Composite
(163) pattern, Component defines a common interface, but Composite often defines a common
implementation. Command (233), Observer (293), State (305), and Strategy (315) are often implemented
with abstract classes that are pure interfaces.

你可能感兴趣的:(如何区分class inheritance和interface inheritance)