什么是mixin,为什么它们有用?

こ雲淡風輕ζ 提交于 2020-10-21 06:30:42

问题:

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
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!