[Xotcl] More usage questions

Gustaf Neumann Gustaf.Neumann at wu-wien.ac.at
Mon Dec 11 16:26:33 CET 2000


>>>>> "L" == Laurent Duperval <laurent.duperval at netergynet.com> writes:

L> Hi,
L> How do I do aggregation of objects? For example, in Java I have

L> class Foo {
L>   Class1 c1;
L>   Class2 c2;
L> }

L> where Class1 and Class2 are two other classes. How do I create the same
L> effect in XOTcl? I've tried a few variations but I don't get the effect I
L> want so I guess I'm doing wrong.


Dear Laurent,

XOTcl supports dynamic aggregation of (a) objects and (b) classes.
Your example resembles a static aggregation of objects (static, since
you can't change the aggregation at runtime).

For object aggregation, one can do:

   Class Class1
   Class Class2

   Class Foo
   Foo instproc init {} {
     Class1 [self]::c1
     Class2 [self]::c2
   }

   Foo f

In order to change the aggregation, one can add new objects

   Object f::o 

The objects form an object tree, which can be disaggregated or moved 
etc. through the copy/move/destroy methods.

In addition to the aggregation of objects, XOTcl allows the
aggregation of descriptive structures (classes) as well

  Class C
  Class C::Foo

  C::Foo instproc ...
  C::Foo proc ...

which supports the same methods for disaggregation etc. like for
object aggregation.

For a more detailed discussion about aggregation in XOTcl see:
http://nm.wu-wien.ac.at/research/publications/sac.pdf


L> Also, how do you create and use private data? By this I mean data (and
L> possibly methods) which are only accessible by the class or the object.

XOTcl has no native support for private data. The idea of private data
conflicts to a certain point with the idea of introspection and
reflection. However, one can achieve a similar behavior through
refinement of the set method (and by deactivating the Tcl set
command). For the refinement you can define for example a set method
on the class level, mixins or filters.

hope this helps
best regards

-gustaf neumann




More information about the Xotcl mailing list