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.
---《Design Patterns: Elements of Reusable Object-Oriented Software 1st Edition》
-
Inheritance, isn't it simply about subclasses 'inheriting' properties and methods from the parent class. How does it become 'an object's implementation in terms of another object's implementation'? When I implement class B inheriting from class A in my code, I don't instantiate any objects at all!
-
Isn't an interface just a special kind of abstract class? (In comparison to abstract classes, interfaces only declare methods and don't declare properties or fields.) When a concrete class implements an interface, isn't it simply a class inheriting the 'interface' and implementing the methods declared in the interface? How does this turn into 'an object can be used in place of another'? When I make class B implement interface A in my code, I don't instantiate any objects at all!
Aucun commentaire:
Enregistrer un commentaire