Logo

Programming-Idioms

History of Idiom 73 > diff from v11 to v12

Edit summary for version 12 by :

Version 11

2015-09-04, 13:02:41

Version 12

2015-09-17, 06:03:37

Idiom #73 Create a factory

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

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;
Demo URL
http://ideone.com/zIruEC