Not able to load classes defined in archive file in Mac OSX using Object.factory

Basile B. b2.temp at gmx.com
Fri Nov 16 17:03:11 UTC 2018


On Friday, 16 November 2018 at 14:55:52 UTC, Aditya wrote:
> On Friday, 16 November 2018 at 14:30:02 UTC, Adam D. Ruppe 
> wrote:
>> PS object.factory sucks and I hope it is removed some day. 
>> There's no plan to do so, but I still wouldn't actually rely 
>> on it... instead, I'd write your own factory function and 
>> registration system, so you control it and will have 
>> reliability to your specific needs.
>>
>> but still if the factory works for you, eh, you can use it.
>
> How can one write own factory function ? Any pointers to this ?
>
> Thanx

for learning purpose you can make very simply a factory function 
based on string comparison.

Object simpleFactory(string className)
{
    import the_module_where_stuff_is_declared;
    import the_module_where_thing_is_declared;

    if (className == "Stuff")
        return new Stuff;
    else if if (className == "Thing")
       return new Thing;
    // and so on
    else return null;
}

although this requires imports so the command line for building 
should include more path using the "-I" cmd line switch.

I propose this solution because making a true factory might be 
too complicated if you just start learning D.


More information about the Digitalmars-d-learn mailing list