The description of the mode can be referred to [1], and the example in delphi will be held below.
Usually the FORM in Delphi is automatic CREATE or write code in the Form to create (usually in the master Form). The following is created with Abstract Factory.
// Unit Abstractf
TabstractFactory = Class Public Function Createform: TForm; Virtual; ABSTRACT;
// Unit Concretefa
Tconcretefactorya = Class (TabstractFactory) Public Function Createform: TForm; Override;
{Tconcretefactoryb}
Function Tconcretefactorya.createform: TForm; Begin Result: = tfrmforma.create (Application); Result.ShowModal; End; // Unit Concretefb
TconcreteFactoryb = Class (TabstractFactory) Public Function Createform: TForm; Override;
{Tconcretefactoryb}
Function TCONCRETEFAACTORYB.CREATEFORM: TFORM; Begin Result: = tfrmFormB.create (Application); Result.ShowModal;
// Main Form
Unit mainfrm;
Interface
Uses Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls, Abstractf;
type TfrmMain = class (TForm) btnConcreteA: TButton; btnContreteB: TButton; procedure btnConcreteAClick (Sender: TObject); procedure btnContreteBClick (Sender: TObject); private {Private declarations} FAbstractFactory: TAbstractFactory; public {Public declarations} end;
Var frmmain: tfrmmain;
IMPLEMENTATION
Uses concretefa, concretefb;
{$ R * .dfm}
Procedure tfrmmain.btnconcreteclick (sender: TOBJECT); begin fabstractfactory: = tconcretefactorya.create; FabstractFactory.createForm; FabstractFactory.Free; End;
Procedure tfrmmain.btncontretebclick (sender: TOBJECT); Begin FabstractFactory: = tconcretefactoryb.create; FabstractFactory.createform; FabstractFactory.Free; End;
End.
[Reference]
1. "Design Mode - Object-Oriented Software Basics"