



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
(Participants). SingleTon. 4 Instance. P 4 PInstance 4. C++ = 1 Static member function 2000/12/14. D R 4. C(Collaborations). P Db 4 Instance.
Typology: Exercises
1 / 7
This page cannot be seen from the preview
Don't miss anything!




,0K L+MNO' P QRSTUVWX Delphi Y Z[!,IJK] ^_`abcdFe !fghij]QR klm!no QR FNSTUV Delphi pM C++qrFN(Static)L<sqrF N!FN class functiond +!FNMN privated I JLtuvw$/0IJFea
Lxyz{| }~ yzL/0yz /0 Me
SingleTon Instance uE/0~ Instance ! uC++<qrFN Static member function2000/12/ % _`i
/0 Instance u
0FN!Á¹JLf¹JÃÄL~¹JÅÆ_ ºÇk È~¹J] IJ~ IJÉ ÊËÌÍyzÎ~ ÏÐÑÒ~Fe%, e /0Í%,^`5ÐÑÒSTUVDelphi create ¹JM NÁÂLÓ,yz create ¹J uÔ a
TSingleton = class public constructor Create; virtual; destructor Destroy; override; end; var Glob_Singleton1: TSingleton;//
implementation
constructor TSingleton.Create; begin if Glob_Singleton1 <> nil then abort else Glob_Singleton1 := Self; end;
destructor TSingleton.Destroy; begin if Glob_Singleton1 = self then Glob_Singleton1 := nil; inherited Destroy; end; Delphi /0IJ Glob_Singleton1 à_ Singleton , ÈxP !~Çk Ó ¦§¡ Tsingleton %,^_}Ó ÈÚyz½ Create ¹JijæIJP C¡ È/0 ºIJM ²o ÈÆ¶·89WXa
(hard-wires)¨% singleton Ó,- ·Fe!.+
È·bc+ÈFe!/0(registry of singleton)singleton %, /0¿{|/0) ~/0)b/01 5 singleton 2 Instance()$ singleton k%å/0)Ù 3 L /0)Ù 3 gh/4}M¡ singleton ÚË 5 %,~·Fe %,E Instance()M| 6 Ó % singleton 1 C¡ Ó$ !Ó singleton %,/0789:Yã ; Register()/0 1 μ_registery NameSingletonPair Lookup() , 1 <=bÓ$ singleton Çk>¸ !IJ°Ó $ singleton 1 Yã; ?μ singleton Dk/0ghL% !_¹J Y ã;p<¹J _kß:^õö?μ~ Z[%, qr Instance ¹JC MySingletonC¡ singleton P_singleton LÄðÉ@!° singleton %n +~¬ ABV²!% singleton yz^_n Ú¤MN^/0 STUV C Delphi uYCW interface uses classes,SysUtils;
type TSingletonList = class(TList);
TSingletonl = class public constructor Create;virtual; destructor Destroy; override; protected function Lookup(PSingleton: TSingletonl): boolean; end;
TChildSingletonl = class(TSingletonl);
var Glob_Singletonlist: TSingletonList; //
implementation
L Lookup()¹JbÓ 1 plSingleton.ClassName = PSingleton.ClassNametD/¦§ TSingleton TChildSingletonl = class(TSingletonl)P8&EFĬ îÄÈ}$P8F ÄG HIJvKY%a
vXe
&'e%, Singleton uCMNOP(Abstract Factory)Q`¸ (Builder)QR(Prototype)2000/12/ http://home.kimo.com.tw/areca_chen/