Created
November 10, 2019 23:10
-
-
Save vinicioslc/0b9728809aaec06065d5b12e248086ee to your computer and use it in GitHub Desktop.
Singleton em Dart
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
class Singleton { | |
static final Singleton _singleton = Singleton._internal(); | |
String message; | |
factory Singleton() { | |
return _singleton; | |
} | |
Singleton._internal(); | |
} | |
void main() { | |
final meuSing = new Singleton(); | |
meuSing.message = "INALTERADA"; // Altera a Referência | |
print('Estado Referência: ${meuSing.message}\n'); | |
Singleton().message = "ALTERADA"; // Altera a instancia global | |
print('Estado Referência: ${meuSing.message}\n'); | |
print('Estado Singleton : ${Singleton().message}\n'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment