File tree Expand file tree Collapse file tree 3 files changed +6
-7
lines changed
Singleton.Conceptual/NonThreadSafe Expand file tree Collapse file tree 3 files changed +6
-7
lines changed File renamed without changes.
Original file line number Diff line number Diff line change @@ -21,8 +21,6 @@ class Singleton
21
21
{
22
22
private static Singleton _instance ;
23
23
24
- private static object _lock = new object ( ) ;
25
-
26
24
private Singleton ( )
27
25
{ }
28
26
@@ -36,12 +34,13 @@ private Singleton()
36
34
//
37
35
// Эта реализация позволяет вам расширять класс Одиночки, сохраняя
38
36
// повсюду только один экземпляр каждого подкласса.
39
- public static Singleton getInstance ( )
37
+ public static Singleton GetInstance ( )
40
38
{
41
- lock ( _lock )
39
+ if ( _instance == null )
42
40
{
43
- return _instance ?? ( _instance = new Singleton ( ) ) ;
41
+ _instance = new Singleton ( ) ;
44
42
}
43
+ return _instance ;
45
44
}
46
45
}
47
46
@@ -52,8 +51,8 @@ static void Main(string[] args)
52
51
// EN: The client code.
53
52
//
54
53
// RU: Клиентский код.
55
- Singleton s1 = Singleton . getInstance ( ) ;
56
- Singleton s2 = Singleton . getInstance ( ) ;
54
+ Singleton s1 = Singleton . GetInstance ( ) ;
55
+ Singleton s2 = Singleton . GetInstance ( ) ;
57
56
58
57
if ( s1 == s2 )
59
58
{
File renamed without changes.
You can’t perform that action at this time.
0 commit comments