what is the Mixin method in Python?
Based on the results I searched from google, it has something to do with the multi inherits.
so based on the multi inherit of Python, we can implement a class called Mixin.
the defination of Mixin: Mixin classes contain only a specific set of functionalities that we want to be able to mix in with other classes to compose a new class.
but it’s so hard to understand what these words means.
用中文解释一下 就是:
Mixin编程是一种开发模式,是一种将多个类中的功能单元的进行组合的利用的方式,这听起来就像是有类的继承机制就可以实现,然而这与传统的类继承有所不同。通常mixin并不作为任何类的基类,也不关心与什么类一起使用,而是在运行时动态的同其他零散的类一起组合使用。
使用mixin机制有如下好处:可以在不修改任何源代码的情况下,对已有类进行扩展;可以保证组件的划分;可以根据需要,使用已有的功能进行组合,来实现“新”类;很好的避免了类继承的局限性,因为新的业务需要可能就需要创建新的子类。
reference:
https://blog.csdn.net/u012814856/article/details/81355935

浙公网安备 33010602011771号