Logo

Programming-Idioms

History of Idiom 73 > diff from v1 to v2

Edit summary for version 2 by :

Version 1

2015-08-21, 04:35:46

Version 2

2015-08-21, 04:46:31

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;
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