问题:
In " Programming Python ", Mark Lutz mentions "mixins". 在“ Python编程 ”中,Mark Lutz提到了“ mixins”。 I'm from a C/C++/C# background and I have not heard the term before. 我来自C / C ++ / C#背景,以前没有听说过这个词。 What is a mixin? 什么是mixin?
Reading between the lines of this example (which I've linked to because it's quite long), I'm presuming it's a case of using multiple inheritance to extend a class as opposed to 'proper' subclassing. 在本示例的两行之间进行阅读(我已经链接到它,因为它很长),我认为这是使用多重继承来扩展类而不是“适当的”子类的一种情况。 Is this right? 这是正确的吗?
Why would I want to do that rather than put the new functionality into a subclass? 为什么我要这样做而不是将新功能放入子类中? For that matter, why would a mixin/multiple inheritance approach be better than using composition? 因此,为什么混合/多重继承方法比使用组合更好?
What separates a mixin from multiple inheritance? 什么将mixin与多重继承分开? Is it just a matter of semantics? 这仅仅是语义问题吗?
解决方案:
参考一: https://stackoom.com/question/2Eox/什么是mixin-为什么它们有用参考二: https://oldbug.net/q/2Eox/What-is-a-mixin-and-why-are-they-useful
来源:oschina
链接:https://my.oschina.net/u/4432649/blog/4320701