3 ms·
Another fundamental flaw in my opinion is the cats-and-dogs analogy frequently used to highlight the use of inheritance in OO. Cats and dogs being mammals is a
by Jean-Philipe 10y ago
Another fundamental flaw in my opinion is the cats-and-dogs analogy frequently used to highlight the use of inheritance in OO.
Cats and dogs being mammals is a taxonomy. It's data, not code. Unfortunately, I see OO programmers coding taxonomies all the time just for the sake of it, ending up with deep inheritance trees of classes without ever taking the step back and asking themselves, why they do it the first place. (e.g. to share functionality or to reuse code)
- willtim 10y agoTaxonomies are common in the real world, so it is natural to try to model them. If the language lacks sum types (the mathematical dual of product types, a.k.a. tagged unions) then programmers are forced into using inheritance to encode it. So I blame the language, not the programmers.
- gregoor 10y agoI understood JP's critique to be more about mixing behaviour with data than about alternative ways of modelling inheritance.
- willtim 10y agoBut Java strongly encourages the mixing of data and behaviour. There is only virtual method dispatch and switch on ints/enums for efficient case analysis. We therefore need complex encodings like the Visitor pattern, if we are to avoid conflating data and behaviour. So again, I blame the language not the programmers.