【发布时间】:2014-02-02 14:45:20
【问题描述】:
我想创建从 Rectangle 类扩展而来的自定义矩形类。 我的错误是类 Rectangle 没有声明性构造函数“矩形”,我已经看到了 Rectangle 类的源代码并且有常量构造函数。 有可能吗?我认为可能的解决方案是使用组合而不是继承。感谢您的回答。
part of Plot;
class PlotRectangle extends Rectangle{
// Rectangle<int> rectangle; // as variant use composition
String color = "red";
PlotRectangle(int left, int top, int width, int height): super.Rectangle(left, top, width, height){
}
PlotRectangle.withColor(int left, int top, int width, int height, this.color): super.Rectangle(left, top, width, height){
this.color = color;
}
void setColor(String color){
this.color = color;
}
}
【问题讨论】:
标签: inheritance dart