Logo

Programming-Idioms

History of Idiom 73 > diff from v3 to v4

Edit summary for version 4 by :

Version 3

2015-08-21, 05:32:37

Version 4

2015-08-21, 17:00:52

Idiom #73 Create a factory for a particular object class

Create a factory named pFact for any sub class of Parent and taking exactly one string str as constructor parameter.

Idiom #73 Create a factory for a particular object class

Create a factory named pFact for any sub class of Parent and taking exactly one string str as constructor parameter.

Code
type Parent = class
    constructor create(const str: string);
end;

type ClassOfParent = class of Parent;

function pFact(ClassType: ClassOfParent; const str: string): Parent;
begin
	result := ClassType.Create(str);
end;
Code
type Parent = class
    constructor create(const str: string);
end;

type ClassOfParent = class of Parent;

function pFact(ClassType: ClassOfParent; const str: string): Parent;
begin
	result := ClassType.Create(str);
end;
Comments bubble
traditional Delphi or Object Pascal had poor compile-time features. The class of construct was the only way to make a factory for a particular object type
Comments bubble
Traditional Delphi or Object Pascal had poor compile-time features. The class of construct was the only way to make a factory for a particular object type
Demo URL
http://ideone.com/zIruEC
Demo URL
http://ideone.com/zIruEC