Builder mode
origin
The Builder mode in Delphi has expanded in the basic Builder mode. For more information on Builder mode, please refer to [Gam ]
purpose
Separation of a complex object with its representation, making the same build process can create different representations
motivation
A builder (Builder) is a bit similar to the concept of striking factories. However, it is different that the generator generates the individual components of a single complicated class by reference to different constructors, and the abstract factories allow you to create a specific class. For example: a building can construct a house, villa, office. You can hire different construction workers to construct brick houses, wooden houses. Although you can specify the shape of the house, size. And other ribs used to construct the department's sectors, not all. For example, build windows, doors, parking lots.
application
The following example introduces an abstract class TabStractFormBuilder and two of its two specific subclass TREDORMBUILDER, TBLueFormBuilder. TabstractFormBuilder declares some types of constructors
Type
TabstractFormBuilder = Class
Private
FFORM: TFORM;
Procedure BuilderformClose (Sender: Tobject; VAR Action: Tclosection);
protected
Function Getform: TFORM; Virtual;
public
Procedure Createform (Aowner: Tcomponent); Virtual;
.................
.
...............
Property Form: TForm ReadForm;
END;
Type
TREDFORMBUILDER = Class (TabstractFormBuilder)
Private
FnextLeft, Fnexttop: Integer;
public
Procedure Createform (Aowner: Tcomponent); OVERRIDE;
Procedure CreatespeedButton; Override;
Procedure CreateEdit; OVERRIDE;
Procedure CreateEdit; OVERRIDE;
END;
Type
TBLueFormBuilder = Class (TabstractFormBuilder)
Private
FnextLeft, Fnexttop: Integer;
public
Procedure Createform (Aowner: Tcomponent); OVERRIDE;
Procedure CreatespeedButton; Override;
Procedure CreateEdit; OVERRIDE;
Procedure CreateLabel; OVERRIDE;
END;
There is a top interface:
· Declare an interface to create an abstract product object: TabstractFormBuilder
¨ TabstractFormBuilder has three abstract factory methods Createform, CreatespeedButton, CreateEdit, CreateEdit
· TBLUEFORMBUILDER, TREDFORMBUILDER Method for creating specific product objects
When running, the client calls a specific class public constructor to create some parts, the modulation method of the specific constructor instance is as follows:
Procedure TFORM1.CREATE3ComponentformusingBuilder (Abuilder: TabstractFormMBuilder); VAR
Newform: TForm;
Begin
With Abuilder Do Begin
Createform (Application);
Createedit;
Createspeedbutton;
CreateLabel;
Newform: = form;
IF newform <> nil the newform.show;
END;
END;