Logo

Programming-Idioms

History of Idiom 73 > diff from v2 to v3

Edit summary for version 3 by :

Version 2

2015-08-21, 04:46:31

Version 3

2015-08-21, 05:32:37

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
auto pFact(T, A...)(A a)
if (is(T: Parent))
{
	return new T(a);
}
Code
auto pFact(T, A...)(A a)
if (is(T==class) && is(T: Parent))
{
	return new T(a);
}
Comments bubble
in D we can cover all the possible constructors using a variadic argument. Parent is checked statically with a constraint.
Comments bubble
in D we can cover all the possible constructors using a variadic argument. Parent is checked statically with a constraint.
Demo URL
http://dpaste.dzfl.pl/9d4241e06f9e
Demo URL
http://dpaste.dzfl.pl/9d4241e06f9e