| · { widget implementation }
·
· { TRedButton }
·
· constructor TRedSpeedButton.Create(AOwner: TComponent);
· begin
· inherited Create(AOwner);
· Font.Color := clRed;
· end;
·
· { TRedEdit }
·
· constructor TRedEdit.Create(AOwner: TComponent);
· begin
· inherited Create(AOwner);
· Font.Color := clRed;
· end;
·
· { TRedLabel }
·
· constructor TRedLabel.Create(AOwner: TComponent);
· begin
· inherited Create(AOwner);
· Font.Color := clRed;
· end;
·
·
· { the concrete factory }
·
· function TORedFactory.CreateSpeedButton(AOwner: TComponent): TSpeedButton;
· begin
· Result := TRedSpeedButton.Create(AOwner);
· end;
·
· function TORedFactory.CreateEdit(AOwner: TComponent): TEdit;
· begin
· Result := TRedEdit.Create(AOwner);
· end;
·
· function TORedFactory.CreateLabel(AOwner: TComponent): TLabel;
· begin
· Result := TRedLabel.Create(AOwner);
· end;
end.
运行的时候,我们的客户程序的实例由类的工厂具体类创建。并且客户程序不需知道使用工厂的具体子类。
Delphi实例
正在组织
上一页 [1] [2] |