A
awfigsk
Unregistered / Unconfirmed
GUEST, unregistred user!
我在看刘艺老师所著的《Delphi面向对象编程思想》一书中有一地方不理解:(第79页)
Factory Method
===============
unit Unit4
interface
...
type
TControlClass=Class of TControl
TControlFactory=class
private
FControlObj:TControl
public
constructor create(AOwner:TWinControl;ControlClass:TControlClass)
end
implementation
constructor TControlFactory.create(AOwner:TWinControl;ControlClass:TControlClass)
begin
FControlObj:=ControlClass.Create(AOwner)
FControlObj.Parent:=AOwner
FControlObj.Name:=FControlObj.ClassName
FControlObj.SetBounds(10,10,250,150)
self:=TControlFactory(FControlObj)
end
end.
unit Unit3
interface
...
implementation
uses Unit4
procedure TForm1.Button1Click(Sender:TObject)
const
ContrlClassArry:array[0..2] of TControlClass=(TMonthCalendar,TMemo,TColorBox)
var
ControlObj:TObject
begin
ControlObj:=TControlFactory.creat(self,ContrlClassAry[RadioGroup1.ItemIndex])
...
end
end.
红色标记的二个地方不太理解,
在第一个红色的地方,self是代表什么呢?是表示TControlFactory类所创建的实例吗?
在第二个红色的地方,create方法会返回的一个地址吗?
还请各位大侠指点,谢谢!
Factory Method
===============
unit Unit4
interface
...
type
TControlClass=Class of TControl
TControlFactory=class
private
FControlObj:TControl
public
constructor create(AOwner:TWinControl;ControlClass:TControlClass)
end
implementation
constructor TControlFactory.create(AOwner:TWinControl;ControlClass:TControlClass)
begin
FControlObj:=ControlClass.Create(AOwner)
FControlObj.Parent:=AOwner
FControlObj.Name:=FControlObj.ClassName
FControlObj.SetBounds(10,10,250,150)
self:=TControlFactory(FControlObj)
end
end.
unit Unit3
interface
...
implementation
uses Unit4
procedure TForm1.Button1Click(Sender:TObject)
const
ContrlClassArry:array[0..2] of TControlClass=(TMonthCalendar,TMemo,TColorBox)
var
ControlObj:TObject
begin
ControlObj:=TControlFactory.creat(self,ContrlClassAry[RadioGroup1.ItemIndex])
...
end
end.
红色标记的二个地方不太理解,
在第一个红色的地方,self是代表什么呢?是表示TControlFactory类所创建的实例吗?
在第二个红色的地方,create方法会返回的一个地址吗?
还请各位大侠指点,谢谢!