mixins
作用:
- 实现多继承
- 组合拼装多个类的功能到一个新的类
案例代码
void main() {
Car1 car1 = new Car1();
car1.work();
car1.info();
}
abstract class Engine{
void work();
}
class ElectricityEngine implements Engine{
@override
void work() {
print("使用电的引擎...");
}
}
class OilEngine implements Engine{
@override
void work() {
print("使用油的引擎...");
}
}
class Tire{
void info(){
print("轮胎...");
}
}
//使用mixins 组合封装新的类
class Car1 = Tire with ElectricityEngine;
class Car2 = Tire with OilEngine;
结果:
使用电的引擎...
轮胎...
Process finished with exit code 0