2013-11-11 01:11:09 +01:00
|
|
|
unit BusinessObjectsU;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2015-01-14 11:39:44 +01:00
|
|
|
ObjectsMappers, Generics.Collections;
|
2013-11-11 01:11:09 +01:00
|
|
|
|
|
|
|
type
|
2014-04-01 00:02:31 +02:00
|
|
|
|
|
|
|
[MapperJSONNaming(JSONNameLowerCase)]
|
2013-11-11 01:11:09 +01:00
|
|
|
TPerson = class
|
|
|
|
private
|
2014-05-22 12:48:44 +02:00
|
|
|
FLastName: string;
|
2013-11-11 01:11:09 +01:00
|
|
|
FDOB: TDate;
|
2014-05-22 12:48:44 +02:00
|
|
|
FFirstName: string;
|
2013-11-11 01:11:09 +01:00
|
|
|
FMarried: boolean;
|
|
|
|
procedure SetDOB(const Value: TDate);
|
2014-05-22 12:48:44 +02:00
|
|
|
procedure SetFirstName(const Value: string);
|
|
|
|
procedure SetLastName(const Value: string);
|
2013-11-11 01:11:09 +01:00
|
|
|
procedure SetMarried(const Value: boolean);
|
|
|
|
public
|
2015-02-16 14:25:09 +01:00
|
|
|
function Equals(Obj: TObject): boolean; override;
|
2014-05-22 12:48:44 +02:00
|
|
|
// [MapperJsonSer('nome')]
|
|
|
|
property FirstName: string read FFirstName write SetFirstName;
|
|
|
|
// [DoNotSerialize]
|
|
|
|
property LastName: string read FLastName write SetLastName;
|
2013-11-11 01:11:09 +01:00
|
|
|
property DOB: TDate read FDOB write SetDOB;
|
|
|
|
property Married: boolean read FMarried write SetMarried;
|
2015-02-16 14:25:09 +01:00
|
|
|
class function GetNew(AFirstName, ALastName: string; ADOB: TDate; AMarried: boolean): TPerson;
|
2015-01-14 11:39:44 +01:00
|
|
|
class function GetList: TObjectList<TPerson>;
|
2013-11-11 01:11:09 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
[MapperJSONNaming(JSONNameLowerCase)]
|
|
|
|
TCustomer = class
|
|
|
|
private
|
2014-05-22 12:48:44 +02:00
|
|
|
FName: string;
|
|
|
|
FAddressLine2: string;
|
|
|
|
FAddressLine1: string;
|
|
|
|
FContactFirst: string;
|
|
|
|
FCity: string;
|
|
|
|
FContactLast: string;
|
|
|
|
procedure SetAddressLine1(const Value: string);
|
|
|
|
procedure SetAddressLine2(const Value: string);
|
|
|
|
procedure SetCity(const Value: string);
|
|
|
|
procedure SetContactFirst(const Value: string);
|
|
|
|
procedure SetContactLast(const Value: string);
|
|
|
|
procedure SetName(const Value: string);
|
2013-11-11 01:11:09 +01:00
|
|
|
public
|
2014-05-22 12:48:44 +02:00
|
|
|
property name: string read FName write SetName;
|
2013-11-11 01:11:09 +01:00
|
|
|
[MapperTransient]
|
2014-05-22 12:48:44 +02:00
|
|
|
property ContactFirst: string read FContactFirst write SetContactFirst;
|
2013-11-11 01:11:09 +01:00
|
|
|
[MapperTransient]
|
2014-05-22 12:48:44 +02:00
|
|
|
property ContactLast: string read FContactLast write SetContactLast;
|
|
|
|
property AddressLine1: string read FAddressLine1 write SetAddressLine1;
|
|
|
|
property AddressLine2: string read FAddressLine2 write SetAddressLine2;
|
|
|
|
property City: string read FCity write SetCity;
|
2013-11-11 01:11:09 +01:00
|
|
|
end;
|
|
|
|
|
2014-05-30 11:29:58 +02:00
|
|
|
[MapperJSONNaming(JSONNameLowerCase)]
|
|
|
|
TProgrammer = class(TPerson)
|
|
|
|
private
|
|
|
|
FSkills: string;
|
|
|
|
procedure SetSkills(const Value: string);
|
|
|
|
public
|
|
|
|
property Skills: string read FSkills write SetSkills;
|
|
|
|
end;
|
|
|
|
|
|
|
|
[MapperJSONNaming(JSONNameLowerCase)]
|
|
|
|
TPhilosopher = class(TPerson)
|
|
|
|
private
|
2015-02-16 14:25:09 +01:00
|
|
|
FMentors: string;
|
|
|
|
procedure SetMentors(const Value: string);
|
2014-05-30 11:29:58 +02:00
|
|
|
public
|
2015-02-16 14:25:09 +01:00
|
|
|
property Mentors: string read FMentors write SetMentors;
|
2014-05-30 11:29:58 +02:00
|
|
|
end;
|
|
|
|
|
2013-11-11 01:11:09 +01:00
|
|
|
implementation
|
|
|
|
|
2015-02-16 14:25:09 +01:00
|
|
|
uses
|
|
|
|
System.SysUtils;
|
|
|
|
|
2013-11-11 01:11:09 +01:00
|
|
|
{ TPerson }
|
|
|
|
|
2015-02-16 14:25:09 +01:00
|
|
|
function TPerson.Equals(Obj: TObject): boolean;
|
|
|
|
begin
|
|
|
|
Result := Obj is TPerson;
|
|
|
|
if Result then
|
|
|
|
begin
|
|
|
|
Result := Result and (TPerson(Obj).LastName = Self.LastName);
|
|
|
|
Result := Result and (TPerson(Obj).FirstName = Self.FirstName);
|
|
|
|
Result := Result and (TPerson(Obj).Married = Self.Married);
|
|
|
|
Result := Result and (TPerson(Obj).DOB = Self.DOB);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2015-01-14 11:39:44 +01:00
|
|
|
class function TPerson.GetList: TObjectList<TPerson>;
|
|
|
|
begin
|
|
|
|
Result := TObjectList<TPerson>.Create;
|
2015-02-16 14:25:09 +01:00
|
|
|
Result.Add(TPerson.GetNew('Tony', 'Stark', EncodeDate(1965, 5, 15), true));
|
2015-01-14 11:39:44 +01:00
|
|
|
Result.Add(TPerson.GetNew('Stevene', 'Rogers', 0, true));
|
|
|
|
Result.Add(TPerson.GetNew('Bruce', 'Banner', 0, true));
|
|
|
|
end;
|
|
|
|
|
2015-02-16 14:25:09 +01:00
|
|
|
class function TPerson.GetNew(AFirstName, ALastName: string; ADOB: TDate; AMarried: boolean): TPerson;
|
2015-01-14 11:39:44 +01:00
|
|
|
begin
|
|
|
|
Result := TPerson.Create;
|
|
|
|
Result.FLastName := ALastName;
|
|
|
|
Result.FFirstName := AFirstName;
|
|
|
|
Result.FDOB := ADOB;
|
|
|
|
Result.FMarried := AMarried;
|
|
|
|
end;
|
|
|
|
|
2013-11-11 01:11:09 +01:00
|
|
|
procedure TPerson.SetDOB(const Value: TDate);
|
|
|
|
begin
|
|
|
|
FDOB := Value;
|
|
|
|
end;
|
|
|
|
|
2014-05-22 12:48:44 +02:00
|
|
|
procedure TPerson.SetFirstName(const Value: string);
|
2013-11-11 01:11:09 +01:00
|
|
|
begin
|
|
|
|
FFirstName := Value;
|
|
|
|
end;
|
|
|
|
|
2014-05-22 12:48:44 +02:00
|
|
|
procedure TPerson.SetLastName(const Value: string);
|
2013-11-11 01:11:09 +01:00
|
|
|
begin
|
|
|
|
FLastName := Value;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TPerson.SetMarried(const Value: boolean);
|
|
|
|
begin
|
|
|
|
FMarried := Value;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ TCustomer }
|
|
|
|
|
2014-05-22 12:48:44 +02:00
|
|
|
procedure TCustomer.SetAddressLine1(const Value: string);
|
2013-11-11 01:11:09 +01:00
|
|
|
begin
|
|
|
|
FAddressLine1 := Value;
|
|
|
|
end;
|
|
|
|
|
2014-05-22 12:48:44 +02:00
|
|
|
procedure TCustomer.SetAddressLine2(const Value: string);
|
2013-11-11 01:11:09 +01:00
|
|
|
begin
|
|
|
|
FAddressLine2 := Value;
|
|
|
|
end;
|
|
|
|
|
2014-05-22 12:48:44 +02:00
|
|
|
procedure TCustomer.SetCity(const Value: string);
|
2013-11-11 01:11:09 +01:00
|
|
|
begin
|
|
|
|
FCity := Value;
|
|
|
|
end;
|
|
|
|
|
2014-05-22 12:48:44 +02:00
|
|
|
procedure TCustomer.SetContactFirst(const Value: string);
|
2013-11-11 01:11:09 +01:00
|
|
|
begin
|
|
|
|
FContactFirst := Value;
|
|
|
|
end;
|
|
|
|
|
2014-05-22 12:48:44 +02:00
|
|
|
procedure TCustomer.SetContactLast(const Value: string);
|
2013-11-11 01:11:09 +01:00
|
|
|
begin
|
|
|
|
FContactLast := Value;
|
|
|
|
end;
|
|
|
|
|
2014-05-22 12:48:44 +02:00
|
|
|
procedure TCustomer.SetName(const Value: string);
|
2013-11-11 01:11:09 +01:00
|
|
|
begin
|
|
|
|
FName := Value;
|
|
|
|
end;
|
|
|
|
|
2014-05-30 11:29:58 +02:00
|
|
|
{ TProgrammer }
|
|
|
|
|
|
|
|
procedure TProgrammer.SetSkills(const Value: string);
|
|
|
|
begin
|
|
|
|
FSkills := Value;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ TPhilosopher }
|
|
|
|
|
2015-02-16 14:25:09 +01:00
|
|
|
procedure TPhilosopher.SetMentors(const Value: string);
|
2014-05-30 11:29:58 +02:00
|
|
|
begin
|
|
|
|
FMentors := Value;
|
|
|
|
end;
|
|
|
|
|
2013-11-11 01:11:09 +01:00
|
|
|
end.
|