Created
May 1, 2020 04:40
-
-
Save roipeker/7f74da934651e473348e9e02db65d207 to your computer and use it in GitHub Desktop.
Dart's factory singleton
This file contains 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
void main(List<String> arguments) { | |
var a1 = Storage(); | |
var a2 = Storage(); | |
print(a1.hashCode); | |
print(a2.hashCode); | |
print(a1==a2); | |
} | |
class Storage { | |
static final Storage _singleton = Storage._internal(); | |
factory Storage() => _singleton; | |
Storage._internal(){ | |
print('initialize code here...'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment