Object.factory
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Tue Sep 29 00:42:23 PDT 2009
How reliable is Object.factory? That is, is there any case where the
compiled program would lose this functionality (some specific
incantation of options to avoid giving the compiler), and is it an
actual part of the language specification for Object or a dmd-specific
"dangerous" feature? I'd much like to know, because I just learned to
love it.
This:
//////////////////////////////////////////////////
public static Command Instance () {
static Command
instance = null ;
if ( instance is null ) {
instance = cast( Command ) factory(
join( [ "app.commands.", ".", "Command" ], capitalize(
Config.command ) )
);
}
return instance;
}
//////////////////////////////////////////////////
Is so much better than a switch statement or a registry for deferred
singletons and the like, despite the (shudder) explicit cast involved.
-- Chris Nicholson-Sauls
More information about the Digitalmars-d-learn
mailing list