Board index » delphi » Static class members. singletons
s...@ksc.net.th (Paul Sjoerdsma)
![]() Delphi Developer |
Thu, 11 Feb 1999 03:00:00 GMT
|
s...@ksc.net.th (Paul Sjoerdsma)
![]() Delphi Developer |
Thu, 11 Feb 1999 03:00:00 GMT
Static class members. singletonsI want to be able to create only one single copy of an object // example from Design Patterns, "Elements od Reusable Software Design" Quote} Singleton* Singleton::Instance() { Quote} Any suggestions???? -- |
Dylan Steinbe
![]() Delphi Developer |
Thu, 11 Feb 1999 03:00:00 GMT
Re:Static class members. singletonsIn article <MPLANET.321f93a1snr989...@news.au.ac.th>, s...@ksc.net.th says... Quote> I want to be able to create only one single copy of an object that only one instance of a class exists. So you can't prevent a programmer using your class from creating additional instances of it. If, however, you want to guarantee that an instance of the class is always type TMyObj = class var implementation initialization |
Olav
![]() Delphi Developer |
Fri, 12 Feb 1999 03:00:00 GMT
Re:Static class members. singletonsQuoteDylan Steinberg wrote: mention. nst : TMyObj; Quote
| | | _ _ http://www.stud.unit.no/~olavb/ |_| |_|_|_|_| Ol...@dds.nl Eyecom Images, Amsterdam finger:Ol...@stud.unit.no |
ROLAND KAUFMA
![]() Delphi Developer |
Fri, 12 Feb 1999 03:00:00 GMT
Re:Static class members. singletonsQuote>I want to be able to create only one single copy of an object not sure if this is 100% correct, because I don't have the compiler here, but it is close type TSingleton = class function TSingleton.Instance; (* variables should be initialized to nil, but in any case *) initialization |
Hallvard Vassbot
![]() Delphi Developer |
Fri, 12 Feb 1999 03:00:00 GMT
Re:Static class members. singletonsQuoteROLAND KAUFMANN wrote: To get around this, use a global variable declared in the implementation section. This makes it private to the unit where the class is defined. As Olav mentions in another message, declare the constructor as private interface implementation var class function TSingleton.Instance: TSingleton; constructor TSingleton.Create; initialization Whether to use a class method, normal function or an interfaced variable to -- |
Phoenix Business Enterpris
![]() Delphi Developer |
Fri, 12 Feb 1999 03:00:00 GMT
Re:Static class members. singletonsQuote>> I'm looking for a comparable method in Delphi upon entry, generate an exception on the constructor. _ Quote>>SQUID - The ultimate 95/NT offline databasing reader |