Dart语言的工厂构造函数
工厂构造函数没有创建一个新的类的实例返回Singleton模式等实例。
如果要创建工厂构造函数,使用factory关键字。
工厂构造函数的示例
void main() {
factconst obj = new factconst();
obj.val=25;
print(obj.val);
}
class factconst{
static factconst fconstuct;
var val;
factory factconst(){
if(fconstuct==null){
fconstuct= new factconst._internal();
}
return fconstuct;
}
factconst._internal(){
}
}
日期:2020-04-11 23:04:02 来源:oir作者:oir
