Smalltalk Metaclasses and inheritance

Joe Graham joe at aiobjects.com
Sat Dec 8 06:58:09 UTC 2001


I have an example use case where I would want to represent the behavior of
different classes in a single class.

According to some approaches this would be the job of the metaclass. Or the
mechanism which represents the Class at runtime.  An example use case is as
follows:
Assuming we have a metaclass for an arbitrary class and we'll call it
"File".
Also, assuming we have a metaclass for a class named "Persistent".
Now assume I have a third class named "ThreadSafe".
How would I represent an object that exhibits the behavior of "Persistent",
"ThreadSafe" "File" through inheritance or otherwise?

Does anyone know where either in Smalltalk or in the squeak source tree
where classes are constructed and resolved?
More specifically if a class is declared how is the class definition
resolved?  For example if it inherits another class how/where are the
instance and method declarations resolved?

<class_metaclass>
 |  <instance_variable_defs>
 \  <method_defs>
  \ <instance_variable_table>
   \<method_table>
    \
  <class_definition>                <subclass_metaclass>
     <instance_variable_defs>       /   <instance_variable_defs>
     <method_defs>                 /    <method_defs>
        \                         /     <instance_variable_table>
         \                       /      <method_table>
          \                     /
           \                   /
           <subclass_definition>
             <instance_variable_defs>
             <method_defs>

As you can see by this cheesy diagram the Class definitions are just
definitions and nothing more.  The actual representation of the method or
instance dictionary is maintained in the so-called metaclass.
Is it possible to modify the metaclass class resolution protocol in
Smalltalk, either at runtime or otherwise?  Can I change how classes are
constructed so I can programmatically decide how methods and instance
variables are resolved?  This would be relevant if I was trying to exhibit
the characteristics of many classes in a single class instance. Maybe this
just has to do with my total lack of understanding of the internal Class
representation mechanism in Smalltalk.  Any explanation of this would be
greatly appreciated.

Regards,
-joe





More information about the Squeak-dev mailing list