Created
June 19, 2019 02:04
-
-
Save ejabu/c3714ef55d388fc52f8b5a3c84e314d6 to your computer and use it in GitHub Desktop.
Factory in Fautter
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
// Ref : https://theburningmonk.com/2013/09/dart-implementing-the-singleton-pattern-with-factory-constructors/ | |
class CommonClass { | |
CommonClass() { | |
print("Init : CommonClass"); | |
} | |
String namaDev; | |
String get getNamaDev { | |
return namaDev; | |
} | |
set setName(String value) { | |
namaDev = value; | |
} | |
} | |
class FactoryClass { | |
static final FactoryClass _singleton = new FactoryClass._internal(); | |
factory FactoryClass() { | |
return _singleton; | |
} | |
String namaDev; | |
String get getNamaDev { | |
return namaDev; | |
} | |
set setName(String value) { | |
namaDev = value; | |
} | |
FactoryClass._internal() { | |
this.namaDev = "Anto"; | |
print("Init : FactoryClass"); | |
} | |
} | |
// class FactoryClass { | |
// String namaDev; | |
// String get getNamaDev { | |
// return namaDev; | |
// } | |
// set setName(String value) { | |
// namaDev = value; | |
// } | |
// } | |
main(List<String> args) { | |
FactoryClass fc1 = new FactoryClass(); | |
print(fc1.getNamaDev); | |
fc1.setName = "hehe"; | |
print(fc1.getNamaDev); | |
FactoryClass fc2 = new FactoryClass(); | |
print(fc2.getNamaDev); | |
FactoryClass fc3 = new FactoryClass(); | |
print(fc3.getNamaDev); | |
print(fc1.getNamaDev); | |
FactoryClass fc4 = new FactoryClass(); | |
CommonClass cc1 = new CommonClass(); | |
CommonClass cc2 = new CommonClass(); | |
CommonClass cc3 = new CommonClass(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment