Advertisement
filhotecmail

InterfaceModelGenericBaseClass

Feb 27th, 2020
663
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 4.27 KB | None | 0 0
  1. unit LeopardGerenciador.BaseClass.InterfaceModelGenericClass.InterfaceModelGenericBaseClass;
  2.  
  3. interface
  4.  
  5.   uses System.classes,
  6.        System.SysUtils,
  7.        System.Types,
  8.        System.Generics.Collections,
  9.        System.Generics.Defaults, LeopardGerenciador.BaseClass.InjectableBaseclass.InjectableBaseClassModel,
  10.        LeopardDriverDataset;
  11.  
  12.    type IModelBaseInterface = Interface
  13.    ['{582E9A29-346C-4B73-9B1A-E24E614E3E43}']
  14.  
  15.      function Inject( InjectDeps: TProc<TObject> ):TInterfacedObject;
  16.      function SetEvents( InjectDeps: TProc<TObject> ):TInterfacedObject;
  17.      function Response( Done: TProc<TObject>; Fail: TProc<Exception> ):TInterfacedObject;
  18.  
  19.      procedure SetDeps(const Value: TInjectableBaseClassModel);
  20.      function getFDeps: TInjectableBaseClassModel;
  21.      property Deps: TInjectableBaseClassModel read getFDeps write SetDeps;
  22.  
  23.      function PrintData:TInterfacedObject;
  24.      function ExportToXml:TInterfacedObject;
  25.      function ExportToCsv:TInterfacedObject;
  26.      function ExportToJson:TInterfacedObject;
  27.  
  28.      function MakeDataset(  Done: TProc<TObject,IModelBaseInterface> ):TInterfacedObject; overload;
  29.      function MakeDataset( const GeneratorName,Field: String ;Done: TProc<TObject,IModelBaseInterface> ):TInterfacedObject; overload;
  30.  
  31.  End;
  32.  
  33.  type TModelBaseObjConcret = class( TInterfacedObject,IModelBaseInterface )
  34.  
  35.   protected
  36.     FDeps: TInjectableBaseClassModel;
  37.     procedure SetDeps(const Value: TInjectableBaseClassModel);
  38.     function getFDeps: TInjectableBaseClassModel;
  39.    public
  40.     class function New: IModelBaseInterface;
  41.     procedure AfterConstruction; override;
  42.     procedure BeforeDestruction; override;
  43.     function Inject( InjectDeps: TProc<TObject> ):TInterfacedObject; virtual; abstract;
  44.     function SetEvents( InjectDeps: TProc<TObject> ):TInterfacedObject; virtual; abstract;
  45.     function Response( Done: TProc<TObject>; Fail: TProc<Exception> ):TInterfacedObject; virtual; abstract;
  46.  
  47.     function PrintData:TInterfacedObject; virtual; abstract;
  48.     function ExportToXml:TInterfacedObject; virtual; abstract;
  49.     function ExportToCsv:TInterfacedObject; virtual; abstract;
  50.     function ExportToJson:TInterfacedObject; virtual; abstract;
  51.  
  52.     function MakeDataset(  Done: TProc<TObject,IModelBaseInterface> ):TInterfacedObject; overload;
  53.     function MakeDataset( const GeneratorName,Field: String ;Done: TProc<TObject,IModelBaseInterface> ):TInterfacedObject; overload;
  54.    published
  55.    property Deps: TInjectableBaseClassModel read getFDeps write SetDeps;
  56.  
  57.  end;
  58.  
  59.   (*Aqui um exemplo de um plugin para Herança multipla,
  60.     podendo extender a classe base sem prejudicar as classes filhas*)
  61.   type ICrudBaseClass = Interface
  62.     ['{884927F2-21A0-4BFD-9696-28FB11EEC86F}']
  63.      function AppendData():TInterfacedObject;
  64.      function PostData():TInterfacedObject;
  65.      function EditData():TInterfacedObject;
  66.      function CancelData():TInterfacedObject;
  67.      function DeleteData():TInterfacedObject;
  68.  
  69.   End;
  70.  
  71.  
  72. implementation
  73.  
  74. { TModelBaseObjConcret }
  75.  
  76. procedure TModelBaseObjConcret.AfterConstruction;
  77. begin
  78.   inherited AfterConstruction;
  79.   FDeps := TInjectableBaseClassModel.Create;
  80. end;
  81.  
  82. procedure TModelBaseObjConcret.BeforeDestruction;
  83. begin
  84.   inherited BeforeDestruction;
  85.     FreeAndNil( FDeps );
  86. end;
  87.  
  88. function TModelBaseObjConcret.MakeDataset(const GeneratorName, Field: String;
  89.   Done: TProc<TObject, IModelBaseInterface>): TInterfacedObject;
  90. begin
  91.  Insert(TLeopardDriverDataset.Create(nil,aTPFiredac,True,GeneratorName,Field),
  92.         FDeps.Response.DataL,length(FDeps.Response.DataL)+1);
  93.  if Assigned(Done) then
  94.     Done(FDeps,Self);
  95.  Result:= Self;
  96. end;
  97.  
  98. function TModelBaseObjConcret.MakeDataset(Done: TProc<TObject,IModelBaseInterface>): TInterfacedObject;
  99. begin
  100.   Insert(TLeopardDriverDataset.Create(nil,aTPFiredac),
  101.         FDeps.Response.DataL,length(FDeps.Response.DataL)+1);
  102.   if Assigned(Done) then
  103.      Done( FDeps,Self );
  104.  
  105.    Result:= Self;
  106. end;
  107.  
  108. function TModelBaseObjConcret.getFDeps: TInjectableBaseClassModel;
  109. begin
  110.   Result:= FDeps;
  111. end;
  112.  
  113. class function TModelBaseObjConcret.New: IModelBaseInterface;
  114. begin
  115.   Result:= TModelBaseObjConcret.Create;
  116. end;
  117.  
  118. procedure TModelBaseObjConcret.SetDeps(const Value: TInjectableBaseClassModel);
  119. begin
  120.   FDeps := Value;
  121. end;
  122.  
  123. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement