· 7 years ago · Jul 13, 2018, 06:56 AM
1public class LiveClient
2{
3 private HttpClient httpClient;
4
5 private readonly string publicKey;
6 private readonly string secretKey;
7
8 private const string baseAddress = "https://my.domain";
9
10 public LiveClient()
11 {
12 httpClient = new HttpClient { BaseAddress = new Uri(baseAddress) };
13 }
14
15 public LiveClient(string publicKey, string secretKey)
16 {
17 this.publicKey = publicKey;
18 this.secretKey = secretKey;
19
20 httpClient = new HttpClient { BaseAddress = new Uri(baseAddress) };
21 }
22
23 public void MyWithOutParamConstructorMethod()
24 {
25 //работает Ñ ÐºÐ¾Ð½Ñтруктором без параметров
26 }
27
28 public void MyParamconstructorMethod()
29 {
30 //работает Ñ Ð¿Ð°Ñ€Ð°Ð¼ÐµÑ‚Ñ€Ð¸Ð·Ð¸Ñ€Ð¾Ð²Ð°Ð½Ð½Ñ‹Ð¼ конÑтруктором
31 }
32}
33
34public class LiveClient
35{
36 private const string baseAddress = "https://my.domain";
37
38 protected HttpClient httpClient { get; private set; }
39
40 public LiveClient()
41 {
42 httpClient = new HttpClient { BaseAddress = new Uri(baseAddress) };
43 }
44
45 public void MyWithOutParamConstructorMethod()
46 {
47 //работает Ñ ÐºÐ¾Ð½Ñруктором без параметров
48 }
49}
50
51public class LiveClient_WithParams:LiveClient
52{
53 private readonly string publicKey;
54 private readonly string secretKey;
55
56 public LiveClient_WithParams(string publicKey, string secretKey) : base()
57 {
58 this.publicKey = publicKey;
59 this.secretKey = secretKey;
60 }
61
62 public void MyParamconstructorMethod()
63 {
64 //работает Ñ Ð¿Ð°Ñ€Ð°Ð¼ÐµÑ‚Ñ€Ð¸Ð·Ð¸Ñ€Ð¾Ð²Ð°Ð½Ð½Ñ‹Ð¼ конÑруктором
65 }
66}
67
68public interface IWithParamConstructorMethod
69{
70 void MyWithOutParamConstructorMethod();
71}
72
73public interface IParamconstructorMethod
74{
75 void MyParamconstructorMethod();
76}
77
78public class LiveClient: IWithParamConstructorMethod, IParamconstructorMethod
79{
80 private HttpClient httpClient;
81
82 private readonly string publicKey;
83 private readonly string secretKey;
84
85 private const string baseAddress = "https://my.domain";
86
87 private LiveClient()
88 {
89 httpClient = new HttpClient { BaseAddress = new Uri(baseAddress) };
90 }
91
92 private LiveClient(string publicKey, string secretKey)
93 {
94 this.publicKey = publicKey;
95 this.secretKey = secretKey;
96
97 httpClient = new HttpClient { BaseAddress = new Uri(baseAddress) };
98 }
99
100 public void MyWithOutParamConstructorMethod()
101 {
102 //работает Ñ ÐºÐ¾Ð½Ñтруктором без параметров
103 }
104
105 public void MyParamconstructorMethod()
106 {
107 //работает Ñ Ð¿Ð°Ñ€Ð°Ð¼ÐµÑ‚Ñ€Ð¸Ð·Ð¸Ñ€Ð¾Ð²Ð°Ð½Ð½Ñ‹Ð¼ конÑтруктором
108 }
109
110 public static IWithParamConstructorMethod CreateLiveClient(string publicKey, string secretKey)
111 {
112 return new LiveClient(publicKey, secretKey);
113 }
114
115 public static IParamconstructorMethod CreateLiveClient()
116 {
117 return new LiveClient();
118 }
119}
120
121LiveClient.CreateLiveClient(..)
122
123public class LiveClient
124 {
125 protected HttpClient httpClient;
126
127 private const string baseAddress = "https://api.livecoin.net";
128
129 public LiveClient()
130 {
131 httpClient = new HttpClient { BaseAddress = new Uri(baseAddress) };
132 }
133}
134
135public class LiveClientPrivate :LiveClient
136 {
137 private static LiveClientPrivate instance;
138 private static object syncRoot = new Object();
139
140 private readonly string publicKey;
141 private readonly string secretKey;
142
143 protected LiveClientPrivate(string publicKey, string secretKey):base()
144 {
145 this.publicKey = publicKey;
146 this.secretKey = secretKey;
147 }
148
149 public LiveClientPrivate Set (string pubKiy, string secKey)
150 {
151 if (instance == null)
152 {
153 lock (syncRoot)
154 {
155 if (instance == null)
156 instance = new LiveClientPrivate(pubKiy, secKey);
157 }
158 }
159
160 return instance;
161 }
162 }