My opinion of Singleton

xiaoxiao2021-03-06  42

Let's talk about what is Singleton mode. It is a single mode, but it is a 29796428 (QiUbole) that is translated, it is a 29796428 (QiUbole) that is translated. 12:26:46. 12:27:00 The main role is that there is only one class and only the only example 29796428 (QiUbole) 12:27:10 This is actually in actual, in fact, there are still some use of 29796428 (QiUbole) 12:27:41 such as, Current users, we should only guarantee that only one 29796428 (QiUbole) 12:27:57 Generally we will often define a global variable for a certain class, or a form, or a form, or a form, or a form, or a form, or a form. 29796428 (QiUBole 12:28:06, but with this parametric variable will bring a lot of questions 29796428 (QiUbole) 12:28:28 First, the convenient namespace cannot be used (this is not in Delphi, no this concept) 29796428 (qiubole) 12:28:39 Second, it is unable to control it. 29796428 (QiUbole) 12:28:53 Using Singleton mode to solve this problem 29796428 (QiUbole) 12:29:11 We all know In Delphi, only class methods, and there is no class variable 29796428 (QiUbole) 12:29:25 called class method, other methods such as C or Java called static method 29796428 (QiUBole) 12: 29: 35delphi adopted SmallTalk叫 法 法, 方法 方法 方法 方法 形 形 12 形 形 形 形 形 形 形 是 形 是 形 是 是 是 是 是 是 是 是 是 是 是 是 是 是 是 是 是 是 是 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 It should be more comparison 29796428 (QiUBole) 12:30:14 such as INITINSTANCE, INSTANCESize, etc. 12:30:35, but Delphi is a little, it is also the most uncomfortable point, it only provides a class method, does not provide static properties, That is the Static Variable 29796428 (QiUbole) 12:31:00, then we have to achieve this only through a discount (this word does not fight, Mom) approach 29796428 (QiUBole) 12: 31: 23C # in this implementation Priv Ate Static Int i; 29796428 (QiUbole) 12: 31: 40Delphi No way, I have to put it in the Implementation below 29796428 (QiUbole) 12:31:56 The variable here, only the class of the current unit can access 29796428 (QiUBole) 12 : 32: 11 is very good, we want it is it, regard it as static bar 29796428 (Qiube) 12: 32: 48singleton's purpose is to control the two points mentioned above, how is it doing? 29796428 (QiUbole) 12:33:07 In fact, it is simple, or you must start with Class Function. 29796428 (QiUbole) 12:33:29 When any use of this object, you must access the object through a static method (class method). Example 29796428 (QiUBole) 12:33:42 We only need to provide the following method, everything is OK 29796428 (QiUBole) 12: 34: 11type tkillall =

转载请注明原文地址:https://www.9cbs.com/read-74848.html

New Post(0)