DIP 45 - approval discussion

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Nov 13 08:29:46 PST 2013


On 11/13/13 2:46 AM, Jacob Carlborg wrote:
> Here is an excerpt of my serialization library, with the relevant code
> for this discussion:
[snip]

To drive the point home: I looked once more over the code and I think 
it's too complicated for what it does. It could be improved as follows.

The key to simplification is using

Object create() const;

from ClassInfo (aka Typeinfo_Class) in addition to

static const(TypeInfo_Class) find(in char[] classname);

in the same type. The procedure would go as follows:

1. Retrieve the ClassInfo object for the class name.

2. Create a default-constructed object by calling create() against the 
object obtained at (1).

3. Cast that Object down to IDeserializable, which is an interface type 
that has methods such as deserialize(Archive).

4. If the cast failed, throw an exception - the object was not designed 
to be deserialized.

5. Otherwise, call deserialize against that object, passing it the archive.

Voila! No need for runtime registration - all user code has to do is 
implement the appropriate interface.

I hope this both clarifies my point about factory being a sensible 
feature, and helps you improve your library.


Andrei



More information about the Digitalmars-d mailing list