Dynamic class creation 
Author Message
 Dynamic class creation

There's something I'd like to do in Smalltalk but can't see to find out how.  It may be
that it cannot be done at all.  Specifically I'd like to have an object create a new class
(as a subclass to an already existing class) at execution time, and have the new class
available for immediate use during the same execution.  Is this possible?

Thanks,
Kevin



Wed, 18 Jun 1902 08:00:00 GMT  
 Dynamic class creation
I guess it is provided you have compiler support at execution time. Send this
message to the existing class
#subclass: <your new class name>
instanceVariableNames: <instance variable names> classVariableNames: <class
variables>
poolDictionaries: <pool dictionay "if there is any">
category: <and category name is you are using non ENVY environment>

if you are using ENVY then this will work fine

 #subclass: <your new class name> instanceVariableNames: <instance variable
names> classVariableNames: <class variables> poolDictionaries: <pool dictionay
"if there is any">



Wed, 18 Jun 1902 08:00:00 GMT  
 Dynamic class creation

Quote:

>There's something I'd like to do in Smalltalk but can't see to find out how.
> It may be
>that it cannot be done at all.  Specifically I'd like to have an object create
> a new class
>(as a subclass to an already existing class) at execution time, and have the
> new class
>available for immediate use during the same execution.  Is this possible?

A couple of people have mentioned doing this with the compiler. Even without
the compiler it's possible by manually assembling the class objects. This is
often done using "lightweight" classes by creating "Behavior new" and setting
the superclass. There was an article years ago about adding breakpoints, and
instance-specific breakpoints into VisualWorks using this technique. You would
create a new subclass of the object, set the compiled method in question to be
a special kind of method, then change the class of the object you wanted to
break on to be your new subclass. It was quite cool.

The other question, of course, is why you want to do this. You can certainly
create new classes at run-time, but it would be more complex to create new
methods associated with them without the compiler. Depending what you're
trying to accomplish, there might be simpler mechanisms.

--

The Object People                       http://www.objectpeople.com                  
613.225.8812(v) 613.225.5943(f)    



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Dynamic Class Creation

2. Dynamic class creation

3. Dynamic class creation

4. dynamic class creation question

5. CLOS and dynamic class creation question

6. Dynamic creation of classes and methods

7. dynamic class hierarchies, dynamic changes to multimethods ?

8. q: dynamic creation of editfields and menuitem.enabled

9. Dynamic control creation (side note)

10. Dynamic control creation

11. Dynamic creation of menu separator

12. Runtime field creation and dynamic assignment

 

 
Powered by phpBB® Forum Software