bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: New By Name


From: Pierre Bacquet
Subject: RE: New By Name
Date: Wed, 24 Sep 2003 09:11:33 +0200

Mike,

> I would like the Java introspection functionality - or at 
> least to be able to
> create an instance of a class from its name. This would mean 
> there is no need
> for "Factories". I call this feature "new by name" because 
> thats what is was
> called in the "ThinkC" platform/language in the early 90s.
> 
> Has there been any discussion or ideas on a good way to do 
> this? Again, in
> the 90s we ported the ThinkC functionality to Windows and 
> Solaris,HP,AIX. We
> impemented this feature in C++ doing 3 things:
> 1) all classes inherited from a single base class (ThinkC and 
> Java style)
> 2) Adding a macro to each header and source file that did 
> some registration
> stuff (so the name could be looked up ina  table to find the 
> code to create
> theobject)
> 3) forced the linker to link these object by explicitly 
> declaring an instance
> somewhere
> 
> An example on how to use it:
> ChildClass cl = (ChildClass)new_by_name("Children_of_ChildClass");

Take a look at the persistence engine. What it does may look like what
you want, since the persistence engine reads the class name from a stream
and then creates a brand new instance of the given class. The persistence
engine also uses registration macros, ...

There are some subtilities (it seems to me that the class name is written
only once and then only short class ids instance of the class name, ...)

HTH,

Pierre.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]