DIP 45 - approval discussion

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Nov 13 01:27:46 PST 2013


On 11/13/13 12:55 AM, Jacob Carlborg wrote:
> On 2013-11-13 05:07, Andrei Alexandrescu wrote:
>
>> Then how do you figure doing this:
>>
>> class Streamable { ... }
>> class Foo : Streamable { ... }
>> class Bar : Streamable { ... }
>> string className = stream.readln();
>> Streamable obj = ...;
>>
>> How do you create obj from className, when className could be either
>> "Foo" or "Bar"? In the general case there could be any number of
>> classes, in different modules.
>
> This requires Object.factory (or equivalent) and that all subclasses
> have been registered as well.

With Object.factory that's taken care of already.

> Since you don't know which subclass
> "className" represents you're forced to deserialize by doing this:
>
> Streamable obj = deserialize!(Streamable)(className);

Again there is a confusion here. The idea was to create an object with 
the dynamic type Foo if the class name was "Foo" and an object with the 
dynamic type Bar if the class name was "Bar". You are glossing over the 
gist of it all with a function call. Are you sure we are talking about 
the same thing?


Andrei



More information about the Digitalmars-d mailing list