有人可以在Dart中写一些关键字的正式定义吗?
在官方的Dart示例中,我只发现:
class TaskElement extends LIElement with Polymer, Observable {
Run Code Online (Sandbox Code Playgroud)
但我仍然无法理解它到底在做什么.
Yog*_*ngh 12
您可以将 mixin 视为 Java 中的接口,也可以将其视为 Swift 中的协议。这是一个简单的示例。
mixin Human {
String name;
int age;
void about();
}
class Doctor with Human {
String specialization;
Doctor(String doctorName, int doctorAge, String specialization) {
name = doctorName;
age = doctorAge;
this.specialization = specialization;
}
void about() {
print('$name is $age years old. He is $specialization specialist.');
}
}
void main() {
Doctor doctor = Doctor("Harish Chandra", 54, 'child');
print(doctor.name);
print(doctor.age);
doctor.about();
}
Run Code Online (Sandbox Code Playgroud)
希望对理解有所帮助。