Factory pattern in D

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 1 04:20:07 PDT 2015


On Friday, 1 May 2015 at 11:01:29 UTC, Chris wrote:
> This aside, how would I get something to load dynamically? It's 
> either "mismatched function return type" or (with type check) 
> "variable X cannot be read at compile time":
>
> void main(string[] args) {
>  auto type = args[1];
>  auto myType = factory!type();
> }
>
> So it's back to classes/interfaces again? Hmmmm.

Obviously, myType's static type and factory's return type can't 
depend on a dynamic value like args[1].

You could let factory return a std.variant.Variant, but at that 
point maybe just go with classes.


More information about the Digitalmars-d-learn mailing list