On Aug 25, 2006, at 7:14 AM, Thorsten Hohage wrote:

Does anyone know of any code hacks that would allow a developer to
instantiate a custom class from within the IDE by name?

example:
dim instance as Object = NewInstanceOfObjectByName("MyCustomClass")

This is an example of something you could implement elegantly with
"first class classes" (classes that are themselves objects). If you
are interested in this capability, sign on to <http://
www.realsoftware.com/feedback/viewreport.php?reportid=ngrccqde>.

Until then, your simplest solution is a dirty big case statement.

Sorry, but IMHO the simplest solution is a "class-factory"

Define a dictionary e.g. in the App (or better some where else, so your code is protable between Applications) and add the classes during start up

Permit me to elaborate. A factory function is a good solution to this, but it doesn't provide what the original person was looking for, which is something more loosely coupled and easily extensible. But first-class classes, suitably designed, do.

If classes were themselves objects, with constructors and able to support polymorphism (a "Shared Interface", meaning the shared methods on the class allow the class to be treated as an instance of a type), then in the class's constructor, it can register itself with the factory, installing itself into the dictionary you suggested, and manufactures instances of itself on request. Now, the factory works as in your solution, but the code is more loosely coupled: you can add new classes, delete classes, whatever, and you never have to change the factory.

Guyren G Howe
Relevant Logic LLC

guyren-at-relevantlogic.com ~ http://relevantlogic.com

REALbasic, PHP, Python programming
PostgreSQL, MySQL database design and consulting
Technical writing and training


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to