Logo

Programming-Idioms

History of Idiom 73 > diff from v10 to v11

Edit summary for version 11 by :

Version 10

2015-09-04, 13:02:16

Version 11

2015-09-04, 13:02:41

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
auto pFact(T, A...)(A a)
if (is(T==class) && 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