Logo

Programming-Idioms

History of Idiom 73 > diff from v324 to v325

Edit summary for version 325 by programming-idioms.org:
[Pascal] pFact -> fact

Version 324

2016-06-12, 16:56:33

Version 325

2016-06-12, 16:57:40

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;
Code
type Parent = class
  constructor create(const str: string);
end;

type ClassOfParent = class of Parent;

function fact(ClassType: ClassOfParent; const str: string): Parent;
begin
  result := ClassType.Create(str);
end;
Demo URL
http://ideone.com/zIruEC
Demo URL
http://ideone.com/pMMUqV