
On Tue, Mar 29, 2022 at 06:23:06AM +1100, Chris Angelico wrote:
If I'm reading this correctly, you're defining a "conflict" as finding two implementations of the same-named method in independent subtrees of inheritance - that is, when you say "class Pizza(Crust, Topping):", you're treating Crust and Topping as completely independent, and if they both define an add_cheese method, that's a conflict.
You've never had pizza with cheesy crust *and* cheese as a topping?
That's not inheritance. That's composition.
I wouldn't call it composition unless it was implemented using composition instead of inheritance. I would call it a *subset* of inheritance. Artima is back up, so people interested in this topic **REALLY** should read what Michele Simionato has to say about it. I'm not going to apologise for dumping so many links here, I think that Michele is really onto something: OOP with inheritance is an important technique to use, but it is also widely over-sold as the solution to maintainability in large software projects and frameworks, especially when you move from single to multiple inheritance. Unfortunately, MI is just as likely to *hurt* maintainability as to help it, hence the move to composition and generics, or more restrictive forms of inheritance such as traits https://pypi.org/project/strait/ Things to know about Python super: Part 1 https://www.artima.com/weblogs/viewpost.jsp?thread=236275 Part 2 https://www.artima.com/weblogs/viewpost.jsp?thread=236278 Part 3 https://www.artima.com/weblogs/viewpost.jsp?thread=237121 Mixins considered harmful: Part 1 https://www.artima.com/weblogs/viewpost.jsp?thread=246341 Part 2 https://www.artima.com/weblogs/viewpost.jsp?thread=246483 Part 3 https://www.artima.com/weblogs/viewpost.jsp?thread=254367 Part 4 https://www.artima.com/weblogs/viewpost.jsp?thread=254507 Setting Multiple Inheritance Straight: https://www.artima.com/weblogs/viewpost.jsp?thread=246488 The wonders of cooperative inheritance, or using super in Python 3 https://www.artima.com/weblogs/viewpost.jsp?thread=281127 Multiple inheritance in Python works the way it does because it is modelling cooperative MI and the MRO and super are the Right Way to handle cooperative MI. That doesn't mean that cooperative MI doesn't have problems. Other languages forbid MI altogether because of those problems, or only allow it in a severely restricted version, or use a more primitive form of super. MI as defined by Python is perhaps the most powerful, but also the most potentially complicated, complex, convoluted and confusing. -- Steve