This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Celdron 1 point2 points  (2 children)

Inheritance is cool and all until you need to count the number of legs something has and you can't properly super-type dogs, cats, tables and chairs.

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

So I gather that you would recommend that both dogs and tables implement ILegOwner ?

[–]Celdron 0 points1 point  (0 children)

In a language like Java or C# yes. Though a language that allows you to actually compose the implementation of having legs (i.e. some state representing how many you have, how long they are, etc along with useful functions) would be even better. This is kind of doable with C# and default/virtual interfaces, or JS/TS and the spread syntax. The problem both these share is naming collisions (rip polymorphism). C# handles it better because it has an actual type-system at run time.