3 ms·
Interfaces are useless in the context of OOP because they don't bring in implementation (or anything else). The beauty of inheritance is implementation reuse.
by kazinator 4y ago
Interfaces are useless in the context of OOP because they don't bring in implementation (or anything else).
The beauty of inheritance is implementation reuse.
In a proper Alan-Kay-Blessed OOP language, the "interface" has no role. Why? Because there is extermely late binding everywhere.
What that means is that if we want an object to be substitutable wherever a Duck is needed, we just need to make it quack like a Duck. It doesn't have to inherit anything.
Interface inheritance is just syntax: a static type system imposed into OOP, which lets you do type checks. Oh! That object cannot be used here; though it quacks like a Duck, it doesn't inherit DuckInterface. Please add DuckInterface, then fix errors (if any) and try again.
Now inheritance is actually useful even when we have the above True Scotsman's Late Binding OOP that doesn't impose static interface cruft on us. Because:
1. It lets you use implementation. Say that quacking like a duck is a complex set of behaviors. Let the specialists develop (and maintain) DuckBase: you just inherit that (and pull in updates once in a while).
2. It gives you a real instance-of dynamic relationship: your object can be asked "are you a duck" at the dynamic type level, and the type system will assure the caller, that "yes". You can't get that if your duck behavior is coming by delegation to an object contained in your DuckLike by composition.
Also, only multiple inheritance is the real deal; single is seriously crippled.
- pjmlp 4y agoI wouldn't call COM useless, it has served as Windows OOP ABI quite well for the last 25 years, to the point of having been copied in some way to other platforms.
- kazinator 4y agoCOM isn't, and doesn't require interface inheritance. COM is based on registering a binary object which quacks in a certain way, under the right GUID symbol so it can be found.
- pjmlp 4y agoIt doesn't require interface inheritance, it supports interface inheritance. The lookup mechanism is a implementation detail, just like in any OOP language with interfaces.
- kazinator 4y agoCOM is an ABI, not a programming language. There is literally nothing in COM that does interface inheritance. The ABI for in-process COM is such that when you use Microsoft C++, you can use certain abstract base classes. Your objects will be binary compatible with COM.
- pjmlp 4y agoCOM is a programming language model exposed as ABI, with language projections, successfully used for 25 years across multiple languages. Basically it is like we are discussing how vtables work over here.