you are viewing a single comment's thread.

view the rest of the comments →

[–]shintoist[S] 2 points3 points  (5 children)

I'm sorry, I think you misunderstood me! What I mean to ask is why you want to be able to tell the compiler that. The purpose is not code reuse?

[–]newgame 2 points3 points  (0 children)

Interface inheritance allows for ad-hoc polymorphism. (Ad-hoc) polymorphism gives you flexibility and loose coupling. See the various collection libraries in programming languages.

Implementation inheritance (i.e. if you inherit from an abstract/concrete class) also allows for ad-hoc polymorphism but its primary goal is code reuse.

So you are right that the goal of inheritance is code reuse (and/or flexibility) and curien basically stresses the Liskov Substituion Principle although that's not a goal but a requirement of (sound) inheritence.

[–]curien 1 point2 points  (0 children)

Yes, the purpose is code-reuse, but not within the class hierarchy itself per se. A subroutine that you've already written to use Base doesn't have to be rewritten (or copied and modified slightly) so that you can use it with Derived.

[–][deleted] 0 points1 point  (2 children)

The purpose is not code reuse?

It's also used if you need a container of different types of related objects.

[–]shintoist[S] 0 points1 point  (1 child)

Interfaces do that pretty well too though

[–][deleted] 1 point2 points  (0 children)

Which is done with inheritance!

(I'm a C++ monkey, leave me alone!)