What is factory constructot in DART
In this article, i am going to explain factory constructor in DART language.
Factory constructor in DART
The factory constructor does not create a new instance of the class bur returns an instance like singleton pattern. If you want to create a factory constructors, then use the factory keyword.
Example of factory constructor
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(){
}
}
|
Output:
Ask Your Question
Got a programming related question? You may want to post your question here