On 11/13/2013 03:48 AM, Andrei Alexandrescu wrote:
On 11/12/13 6:26 PM, Timon Gehr wrote:
On 11/13/2013 03:15 AM, Andrei Alexandrescu wrote:
...
- If I know the fully qualified name of a class, there are better
ways
to instantiate this class than passing a string containing that
name to
Object.factory in order to call the default constructor.

What are the better ways?

Call the default constructor. Call a delegate/virtual function that
calls the default constructor.

Wait, doesn't Object.factory call the default constructor of the created
object?
...

Yes, I was listing some ways to do this that I think are better than
calling Object.factory.

OK I think I figure you are confused.

I'm not.

You can't call the default
constructor of an object you don't know the type of.

Andrei


Indeed. There was a premise stating that I do. :o)

In any case, the only use for string -> new object is when there is some kind of parsing going on (and then you should make sure in some way that only objects of types in some well-defined subset can be constructed), otherwise you can always pass around richer data structures, such as an actual factory object.

Reply via email to