DIP 45 - approval discussion
Jacob Carlborg
doob at me.com
Wed Nov 13 00:55:29 PST 2013
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. Since you don't know which subclass
"className" represents you're forced to deserialize by doing this:
Streamable obj = deserialize!(Streamable)(className);
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list