D语言有'别名...'。Go 有嵌入的字段。在下面的代码中,Dart 是否有办法在不经过内脏的情况下到达啮齿动物的大肠?理想情况下,以某种方式公开内部组件的集合,无需在每个动物中使用一些通用的内部组件创建转发呼叫?
import 'dart:io';
class Stomach {
work() { print("stomach"); }
}
class LargeIntestine {
work() { print("large intestine"); }
}
class SmallIntestine {
work() { print("small intestine"); }
}
class Guts {
Stomach stomach = new Stomach();
LargeIntestine largeIntestine = new LargeIntestine();
SmallIntestine smallIntestine = new SmallIntestine();
work() {
stomach.work();
largeIntestine.work();
smallIntestine.work();
}
}
class Rodent {
Guts guts = new Guts();
work() => guts.work();
}
main() {
Rodent rodent = new Rodent();
rodent.guts.largeIntestine;
rodent.work();
}