Last active
March 24, 2019 07:06
-
-
Save benznest/14517b3eb0d72f8da917448368b39e22 to your computer and use it in GitHub Desktop.
Factory constructor in Dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Universe{ | |
String name; | |
static Universe u = Universe.init(); | |
factory Universe(){ | |
return u; | |
} | |
Universe.init(){ | |
name = "A"; | |
} | |
} | |
void main() { | |
Universe u1 = Universe(); | |
Universe u2 = Universe(); | |
u1.name = "B"; | |
print(u1.name); // "B" | |
print(u2.name); // "B" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment