DIP 45 - approval discussion

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Nov 13 10:46:38 PST 2013


On 11/13/13 10:41 AM, Dmitry Olshansky wrote:
> 13-Nov-2013 13:27, Andrei Alexandrescu пишет:
>> 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.
>
> I have to chime in.
>
> Serialization != calling default constructor by name.

Of course not. It does give you access to an object with the correct 
dynamic type, and interfaces and virtual calls take care of the rest.

> You have to work out fields somehow - Object.factory doesn't help with
> that. What serialization needs is some hook - be it delegete or whatnot:
>
> Object deserialize(SomeStreamingAbstraction here);

Or a method.

> Simply snatching a name is not serialization. Not to mention that far
> too many protocols are not text.

Method.

> Keeping built-in map of class-name --> "create via default constructor"
> is an awful example of ONE SIZE FITS ALL. It doesn't!

It is: it achieves virtual construction, the only missing piece in a 
classic OOP scheme. Once you have the object, the rest is smooth sailing.

> Simply on the ground of "solves problem in too narrow scope for a hefty
> coast to the user" I'd drop it.

It's good. Let's keep it.



Andrei



More information about the Digitalmars-d mailing list