3 ms·
His argument against inheritance seems based largely on Python's weak implementation of private attributes. No, it seems like a Python-based example of one of
by ubernostrum 9y ago
His argument against inheritance seems based largely on Python's weak implementation of private attributes.
No, it seems like a Python-based example of one of the well-known problems with inheritance, which applies even in languages like Java and C++ with explicit compiler-enforced visibility modifiers. Difficulty determining which class in a hierarchy is responsible for a particular member is not only a Python problem, or an "only languages without explicit public/private/protected" problem. One reason why composition is favored -- and remember, "composition over inheritance" goes back to the GoF book and earlier! -- is clearing this up.
Of course, blindly "composing" is also bad, which is what this post points out.
- pseudalopex 9y agoYou're right that visibility modifiers don't solve the general problem, but the author specifically says "Inheritance is bad... because it leaves each layer nowhere to put its internal state".