It is still an example in Java and pattern, (by java and pattern Yan Hong) The following is the code converted to delphi, and this time I added a comment:)
unit BuilderPattern;
interface
type
TPRoduct = class;
//Abstract builder specification interface
TBuilder = class(TObject)
public
procedure builderpart1(); virtual; abstract;
procedure builderpart2(); virtual; abstract;
function returnProduct(): TProduct; virtual; abstract;
end;
//Create the specific creator class and components together, so that the client does not need to know the specific construction details
TConcreteBuilder = class(TBuilder)
Private
product: TProduct;
public
procedure builderpart1(); override;
procedure builderpart2(); override;
function returnProduct(): TProduct; override;
end;
//Products
TProduct = class(TObject)
//
end;
//The director role is directly used by the client
TDirector = class(TObject)
Private
Builder: TBuilder;
public
procedure Initialize();
end;
Implementation
{ TDirector}
procedure TDirector.Initialize;
Begin
Builder := TConcreteBuilder.Create;
Builder.builderpart1();
Builder.builderpart2();
Builder.returnProduct;
end;
{ TConcreteBuilder }
procedure TConcreteBuilder.builderpart1;
Begin
// your code
end;
procedure TConcreteBuilder.builderpart2;
Begin
// your code
end;
function TConcreteBuilder.returnProduct: TProduct;
Begin
Results := product;
end;
end.