New implementation

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
auto fact(T, A...)(A a)
if (is(T==class) && is(T: Parent))
    return new T(a);
type ParentFactory func(string) Parent

var fact ParentFactory = func(str string) Parent {
	return Parent{
		name: str,
type Parent = class
  constructor create(const str: string);

type ClassOfParent = class of Parent;

function fact(ClassType: ClassOfParent; const str: string): Parent;
  result := ClassType.Create(str);
def fact(a_class, str_):
    if issubclass(a_class, Parent):
        return a_class(str_)
def fact(klass, str) if klass.is_a?(Parent)