We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c46cc84 commit b2143cdCopy full SHA for b2143cd
patterns/singleton/conceptual_dart_style/main.dart
@@ -0,0 +1,10 @@
1
+import 'pattern/singleton.dart';
2
+
3
+void main() {
4
+ // dart style
5
+ Singleton().doSome();
6
7
8
+ // standard style
9
+ Singleton.instance.doSome();
10
+}
patterns/singleton/conceptual_dart_style/pattern/singleton.dart
@@ -0,0 +1,23 @@
+abstract class Singleton {
+ factory Singleton() {
+ if (_instance == null) {
+ print('Create singleton once.');
+ _instance = ConcreteSingleton();
+ }
+ return _instance!;
11
+ static Singleton get instance => Singleton();
12
13
+ void doSome();
14
15
+ static Singleton? _instance;
16
17
18
+class ConcreteSingleton implements Singleton {
19
+ @override
20
+ void doSome() {
21
+ print('doSome()');
22
23
0 commit comments