File tree 3 files changed +23
-2
lines changed 3 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ My realizations of design patterns:
5
5
- [ ] #Builder
6
6
- [x] #FactoryMethod
7
7
- [ ] #Prototype
8
- - [ ] #Singleton
8
+ - [x ] #Singleton
9
9
10
10
- Structural Patterns
11
11
- [ ] #Adapter
Original file line number Diff line number Diff line change
1
+ namespace Singleton . Classes
2
+ {
3
+ public class Singleton
4
+ {
5
+ private static Singleton _instance ;
6
+ public string Name { get ; set ; }
7
+ private Singleton ( )
8
+ {
9
+
10
+ }
11
+
12
+ public static Singleton Instance => _instance ?? ( _instance = new Singleton ( ) ) ;
13
+ }
14
+ }
Original file line number Diff line number Diff line change @@ -6,7 +6,14 @@ class Program
6
6
{
7
7
static void Main ( string [ ] args )
8
8
{
9
- Console . WriteLine ( "Hello World!" ) ;
9
+ var isntance = Singleton . Classes . Singleton . Instance ;
10
+ isntance . Name = "Instance" ;
11
+
12
+ Console . WriteLine ( isntance . Name ) ;
13
+
14
+ var secondIsntance = Singleton . Classes . Singleton . Instance ;
15
+
16
+ Console . WriteLine ( secondIsntance . Name ) ;
10
17
}
11
18
}
12
19
}
You can’t perform that action at this time.
0 commit comments