On Friday, 16 November 2018 at 14:55:52 UTC, Aditya wrote:
How can one write own factory function ? Any pointers to this ?

Something like

Interface delegate()[string] factories;

Interface create(string className) {
    if(className in factories)
       return factories[classname];
    else
       return null; // or throw if you prefer
}



In every module in which you create a class, you will want to add code like this:

class Class : Interface {}

// register with the factory in a module constructor
static this() {
   factories["Class"] = Interface delegate() {
       return new Class();
   }
}


And it should work.

Reply via email to