object vs class oriented -- xotcl

William Pursell bill.pursell at gmail.com
Thu Jan 24 15:35:44 EST 2008


I've been away from Python for at least a year, and in the interim
have spent a little time looking at the XOTcl object framework for
Tcl.  One of the interesting features of XOTcl is the ability for an
object to change class dynamically.  The XOtcl documentation makes the
claim that this makes it object oriented, while most other languages
are "class oriented".  Here's a snippet from the wiki, from a post to
the mailing list by Gustaf Neumann: (http://wiki.tcl.tk/1297)

Class-oriented means: look at the class and you know exactly how all
of the instances look alike. The class is the first and primary
language construct; the class is well the place where you specify the
instance variables (there are no instance variables except those
specified in the class). The only kind of individualism left in the
objects is to let them differ by their state (the values of their
instance variables). Changing classes (class migration) is
conceptually quite hard for this setup.

Object-oriented (in this distinction) means that the primary elements
are objects, which keep all instance variables. classes my be used to
specify the behavior of objects, they are container for methods and
they control the life-cycle of objects. Objects are like the facts,
and classes are like rules, that determine the behavior of the
objects. Since the connection between objects and classes is rather
loose, it is sufficient to define their relation through an
association. Therefore it is quite easy to change the relation between
objects and classes (and between classes and classes) dynamically.
Objects have arbitrary individualism, they may have variables never
used in any class, they may have private procs etc.

I'm not sure that describes the method well.  Basically, you can
instantiate an object A of class Foo, and later change A to be an
object of class Bar.   Does Python support this type of flexibility?
As I stated above, I've been away from Python for awhile now, and am a
bit rusty,  but it seems that slots or "new style" objects might
provide this type of behavior.  The ability to have an object change
class is certainly  (to me) a novel idea.  Can I do it in Python?



More information about the Python-list mailing list