Y
yyanghhong
Unregistered / Unconfirmed
GUEST, unregistred user!
The singleton design pattern defines a variation to the normal Object - Class relation.
The variation is that the class creates only one object for all the application,
and returns that one object any time someone requests an object of that class
eg
Type
TSingleton = class(TObject)
Private
Procedure Dispose;
protected
Procedure Init;
Virtual;
Procedure BeforeDestroy;
Virtual;
Public
class Function NewInstance: TObject;
Override;
Procedure FreeInstance;
Override;
end;
TInterfacedSingleton = class(TInterfacedObject, IUnknown)
Private
Procedure Dispose;
protected
Procedure Init;
Virtual;
Public
class Function NewInstance: TObject;
Override;
Procedure FreeInstance;
Override;
Function _AddRef: Integer;
stdcall;
Function _Release: Integer;
stdcall;
end;
i want to use this pattern in multi thread appliction.
so i am wondering that if it is thread safe,
The variation is that the class creates only one object for all the application,
and returns that one object any time someone requests an object of that class
eg
Type
TSingleton = class(TObject)
Private
Procedure Dispose;
protected
Procedure Init;
Virtual;
Procedure BeforeDestroy;
Virtual;
Public
class Function NewInstance: TObject;
Override;
Procedure FreeInstance;
Override;
end;
TInterfacedSingleton = class(TInterfacedObject, IUnknown)
Private
Procedure Dispose;
protected
Procedure Init;
Virtual;
Public
class Function NewInstance: TObject;
Override;
Procedure FreeInstance;
Override;
Function _AddRef: Integer;
stdcall;
Function _Release: Integer;
stdcall;
end;
i want to use this pattern in multi thread appliction.
so i am wondering that if it is thread safe,