Implementation
D

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating resource.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
type ParentFactory func(string) Parent

var fact ParentFactory = func(str string) Parent {
	return Parent{
		name: str,
	}
}
def fact(a_class, str_):
    if issubclass(a_class, Parent):
        return a_class(str_)
def fact(klass, str)
  klass.new(str) if klass.is_a?(Parent)
end
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;