Registriert seit: 6. Apr 2011
Ort: Berlin
3.070 Beiträge
Delphi 10.4 Sydney
|
AW: Cleancode, Dependency Injection oder wie stelle ich mich richtig an
13. Mai 2014, 14:31
Einfach in verschiedene Units aufteilen?!?
Delphi-Quellcode:
unit Component;
interface
uses
System.Classes,
SettingsSaver;
type
TMyPageControl = class(System.Classes.TComponent)
private
FSettings : TControlSettings;
end;
implementation
end.
Delphi-Quellcode:
unit SettingsSaver;
interface
uses
System.Classes;
type
TControlSettings = class(TObject)
strict private
type
TYourDatabase = class(TObject)
function Save(AUserID : Integer) : Boolean;
end;
private
FDatabase : TYourDatabase;
public
function SaveSettingstoDatabase : Boolean;
end;
implementation
uses
User;
function TControlSettings.SaveSettingstoDatabase : Boolean;
begin
Result := FDatabase.Save(User.GetUserID)
end;
function TControlSettings.TYourDatabase.Save(AUserID : Integer) : Boolean;
begin
Result := AUserID > 0;
end;
end.
Delphi-Quellcode:
unit User;
interface
function GetUserID : Integer;
implementation
function GetUserID : Integer;
begin
Result := 1234;
end;
end.
|