Created
April 26, 2022 14:07
-
-
Save felipecastrosales/afe80bcb8029b24fe10d3578a66be672 to your computer and use it in GitHub Desktop.
Singleton
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 SingletonOne { | |
SingletonOne._privateConstructor(); | |
static final _instance = SingletonOne._privateConstructor(); | |
factory SingletonOne() { | |
return _instance; | |
} | |
} | |
class SingletonTwo { | |
SingletonTwo._privateConstructor(); | |
static final _instance = SingletonTwo._privateConstructor(); | |
static SingletonTwo get instance => _instance; | |
} | |
class SingletonThree { | |
SingletonThree._privateConstructor(); | |
static final instance = SingletonThree._privateConstructor(); | |
} | |
void main() { | |
SingletonOne one = SingletonOne(); | |
SingletonTwo two = SingletonTwo.instance; | |
SingletonThree three = SingletonThree.instance; | |
print(one); | |
print(two); | |
print(three); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment