我想调用从three
类方法导入到two
类文件的one
类方法。
我尝试过,但这是错误的。
文件名:one.dart
import 'two.dart';
class one{
main(){
return two().three().add();
}
}
文件名:two.dart
import 'three.dart';
class two extends one{
static three = new three();
}
文件名:three.dart
class three extends two{
void add(int a, int b){
}
}
我想从类add
中调用one
方法。怎么做?请帮忙吗?
答案 0 :(得分:0)
three
是静态的。 two().three()
=> two.three()
three
是一个属性。 two.three()
=> two.three
add
方法的add()
=> add(1, 2)
//仅以数字为例three
属性名称和three
类名称相同。 class three
=> class Three
缺少三个类型。 static three
=> static Three three
class one{
main(){
return two.three.add(1, 2);
}
}
class two extends one{
static Three three = new Three();
}
class Three extends two{
void add(int a, int b){
}
}
但是,对于良好的OOP,有依赖关系反转原则,即高级模块不应依赖于低级模块。 您的代码现在违反了这一原则。因此,我不建议您使用当前的代码。