View · Search · Index
No registered users in community xowiki
in last 10 minutes

Re: [Xotcl] representing graphs in xotcl...

From: Artur Trzewik <>
Date: Tue, 06 Nov 2007 20:15:56 +0000


Using nested objects to represent graphs could be good solution if you
do not plan to move objects (change graph connection after creating).
Consider that the "rename" method create new objects by copy (see some
old messages in this mailing group)

The standard approach is using association as reference.
The biggest problem is synchronizing references (but there are also
standard solution for this problem from another languages)

Class Node
Node n1
Node n2
Node n2
n2 set parent n1
# use list to store N side of association
n3 set children [list n1 n2]

You can design same helper methods, parameters or even slots to manage it.

# using nested objects

Class Node
Node parent
Node parent::child_for_ever

Using nested objects is good because of simply object lifetime management.
I prefer nested objects when I want to have some control about
destroying groups of objects.

parent destroy
# all children were destroyed too


> Hi,
> I have a need to represent a directed graph in XoTcl.
> '-childof' functionality seems to work well to represent trees.
> Unless I misunderstand, it seems this will force an class-object to
> belong to a single parent (1-to-many relationship).
> Is there a way to represent multiple parents (many-to-many
> relationship) without making multiple copies of nodes along the way?
> Any help is appreciated.
> thanks,
> -shishir
> ------------------------------------------------------------------------
> _______________________________________________
> Xotcl mailing list