Dart mixins
mixins:
Dart支持混入模式,混入是的顺序是从右到左依次执行,而且和super方法是否执行有关。当多种关键字同时实现时,按照出现顺序应该为:extents => mixins => implements
abstract class Base {
a(){
print("Base a()!");
}
b(){
print("Base b()!");
}
c(){
print("Base c()!");
}
}
class A extends Base{
a(){
print("A a()!");
}
b(){
super.b();
print("A b()!");
}
}
class A2 extends Base{
a(){
print("A2 a()!");
super.a();
}
}
class B extends Base{
a(){
print("B a()!");
super.a();
}
b(){
super.b();
print("B b()!");
}
c(){
print("B c()!");
super.c();
}
}
//mixin because it extends a class other than Object.
//https://medium.com/@amandeepkochhar/flutter-dart-the-class-cant-be-used-as-a-mixin-because-it-extends-a-class-other-than-object-a53eb5f214b0
//M集成了B然后混入了A和A2
//方法a输出顺序:A2 、A、B、Base
class M extends B with A, A2{
}