Punning on memory layouts, a la PyObject_HEAD or some of the objects in V8. With this approach, you make sure that all related types have the same memory layout for a subset of fields at the beginning of the struct. Then, a reinterpret_cast on a pointer to one member of the type will yield the same values as a different member of the type, and so can be used generically by code that depends only upon those members. (You have to be very careful with this approach, because multiple inheritance and vtables will usually break it, but if you absolutely positively must have zero-overhead runtime polymorphism it's occasionally the best option.)
#include and preprocessor magic to redefine symbols based on preprocessor defines. Used to be the old way to swap out different implementations of a cross-platform interface, but seems to have largely fallen out of favor in the last couple decades.
Linker magic to accomplish the same, where the header file defines a common interface but the linker may link with one of several different object files to implement that interface at link time. This one is still fairly commonly used; Google and Facebook both have their own custom STL & libstdc++ implementations, and this is also commonly used to swap out eg. malloc implementations.
dlopen & dlsym to do this at runtime. Header file defines the interface, dlsym gives you back a function pointer or set thereof for a plugin implementation.
You see it at 9:44. Where he creates the concept_t and int_model_t inherits from it.
You need an office. You could create a new office from scratch, or you could also just put a desk in a room in your house and give it a unique address like "Suite 1". Now it's both a Room and a HomeOffice.
But if your HomeOffice exposes a method BuildWall(), which mutates the office into a collection of two Rooms, then it would stop fitting the definition of a Room after calling that method.
I don't know if there are different tax consequences for one-room vs. multi-room home offices, but that's one area where the distinction could at least conceivably be significant enough to affect whether you'd prefer to build a separate office or inherit the old room, or maybe just rent an existing office from a third party.
But I don't agree with the "that's an interface, not inheritance" argument. Well designed super classes tend to provide an interface - they just don't use the "interface" keyword.
If you declare a method as abstract, you're defining an interface that subclasses use to define new behaviour. You see this all the time. If a method is defined as protected, you're saying "I'm allowing subclasses to use this interface to change behaviour".
For example, test frameworks usually provide an overridable method that's run before each test - setUp. That's interface - "I will call setUp before every test - feel free to override it".
To me, that's where shit gets hard. It has to have a well defined interface, it has to be an is-a relationship and it has to be a subtype (Liskov). That's why we see composition over inheritance because it's far simpler to just drop one of the constraints and get decent work done.
To some extent, it's a distinction without a difference - at a semantic level, Java only distinguishes between interfaces and purely abstract base classes because one allows multiple inheritance and the other doesn't, and the separate "inherits" and "implements" keywords flow from there. Other languages (like C# and Kotlin) distinguish between interfaces and overridable classes for the purposes of deciding when to allow multiple inheritance, but use the same syntax and terminology for inheriting from both interfaces and base classes. Still other languages make no structural distinction, but still use the word "interface" to refer to base classes that don't include any implementation, and therefore aren't so susceptible to the diamond inheritance problem. TBH, I think the Java-style treatment is the least conceptually consistent, since it's entirely possible to "inherit" a base class without inheriting a single bit of information, either because everything it declares is abstract or because everything got overridden.
There's a pretty decent coverage of all the grotty details of this concept space, and how different languages treat it, in the beginning of the gang of four book.
When you implement interfaces you have to explicitly implement all methods. If you implement them correctly all methods using them continue to stay correct (including C# extension methods or java interface default methods).
With class inheritance you have two large problems: you also inherit state that you might not need, might not have access too and might change in future versions of your base class.
Secondly you might need to override methods of the base class to provide correctness. If your base class adds/changes methods your subclass can easily behave wrongly.
Never looked at it that way. With inheritance, you're essentially re-using behavior that treats like things with like properties in a similar way. With interfaces, you are providing unique, black-boxed behavior that conforms to an operational specification.
Interfaces are also more externalized. They are intended for consumption from outside of any particular class hierarchy, and don't necessarily represent like things nor operate on the internal properties of a particular class or hierarchy.
OTOH, consider the use of inheritance wherein a major operation or algo is implemented and exposed via a public method on an abstract base class, but one or more type-specific abstract methods on which the algo depends is implemented by subclasses in a type-specific way. This more "inverted" structure probably better highlights a distinction with a real difference. Your subclasses are inheriting major behaviors and "tweaking" the behavior as needed.
You could probably pull this off with interfaces, but it's more convoluted. You'd have one class with several external classes that implement some interface and have reduced access to properties of the original class. So, you may now have to expose properties that you'd otherwise prefer not to. And, you have to manage instantiation of the appropriate interface-implementing classes.
>it's entirely possible to "inherit" a base class without inheriting a single bit of information
Sure, you can override every method in a base class, essentially rendering it not inheritance. But, you could also not extend anything at all and opt not to use interfaces or any other OO-construct. It comes down to design.
No. This is what former C/C++ programmers coming to Java typically believe (some of them even after spending 10 years coding in Java, because old habits die hard).
interface = interface
abstract base class = implementation
Interface and implementation may seem like "a distinction without a difference", because one is just a list of method headers and the other is a list of method headers with method bodies, but semantically they are the opposite of each other.
I'd hardly call it a design to aspire to.
I'd probably compare it more closely with a system where everything receives a mutable God object.
My 91 pickup and 99 minivan's engines are still going strong with well over 200k miles, rarely having anything major wrong with them in the entire time I own them, whereas my 2004 and 2009 cars both with ~100k miles have been nothing but total maintenance nightmares. Timing issues, computer failures. Sheer nightmares.
This is the inheritence I find most powerful in software. These things aren't the same but if we treat them the same, the downstream and upstream code are simpler, easier to replace and consistent. I don't worry too much about the philisophical relationship between the objects.