什么是Mixin
关键字: mixinMixin是一种将某个类中的方法混入其他类中的软件开发风格。简单的说,就是一个类可以使用其他类的方法。这个初听起来有点像类的继承,但是这与传统的类继承的方式不一样。
首先,Mixin不是类的继承。传统的,一个类A继承了某个类B,那么A就可以直接调用B中的非private的方法。但是在Mixin中,A与B没有继承关系,而A却能使用B的非private的方法。
其次,Mixin的这些行为是在运行时发生的,而不是静态指定的。
In object-oriented programming languages, a mixin is a class that provides a certain functionality to be inherited by a subclass, but is not meant to stand alone. Inheriting from a mixin is not a form of specialisation but is rather a means to collect functionality. A subclass may even choose to inherit most or all of its functionality by inheriting from one or more mixins through multiple inheritance.A mixin can defer definition and binding of methods until runtime, though attributes and instantiation parameters are still defined at compile time. This differs from the most widely-used approach, which originated in the programming language Simula, of defining all attributes, methods and initialization at compile time.
Mixins were first used in Flavors, which was an approach to object-orientation used in Lisp Machine Lisp. The advantage of mixins is that they encourage code reuse and avoid well-known pathologies associated with multiple inheritance. However, mixins introduce their own set of compromises.
发表评论
- 浏览: 17230 次
- 性别:

- 来自: 杭州

- 详细资料
搜索本博客
我的相册
共 7 张
最新评论
-
[摘]正确的创业者心态
ddd 写道》不过,如果这旧调本身不错,多弹几次,又有什么关系呢? 楼主看过古龙 ...
-- by spyker -
[摘]正确的创业者心态
》不过,如果这旧调本身不错,多弹几次,又有什么关系呢?楼主看过古龙的书,鉴定完毕 ...
-- by ddd -
无意中网上看到一篇关于ge ...
有很多必要的功能必须使用特定的插件,而这些插件又不是缺省安装必带的,所以用起来很 ...
-- by SteveGY -
无意中网上看到一篇关于ge ...
姜太公 写道可惜它的给关键字等加的颜色太难看。还有很多重复的gedit失败的地方 ...
-- by seen -
无意中网上看到一篇关于ge ...
可惜它的给关键字等加的颜色太难看。还有很多重复的
-- by 姜太公






评论排行榜