Begin main content
Search · Index
No registered users in community xotcl-mailing-list
in last 10 minutes

Re: [Xotcl] Children object shadows parent objects method

From: Kristoffer Lawson <setok_at_fishpool.com>
Date: Wed, 22 Nov 2006 16:48:54 +0200 (EET)

On Wed, 22 Nov 2006, V.K.Vallinayagam wrote:

> Here is a sample code.
> Object a
> Object a proc name {} {
> return "I am valli"
> }
> a name # returns "I am valli"
> Object a::name # Child object with same name as the proc
> a name # returns ::a::name and not the previous message
> Is this the desired behaviour. Is there any workaround.

It's probably not desirable but if you think about it, you can see why
that is happening. Objects are basically implemented as namespaces (well,
at least they were at some point). A method is a proc inside a namespace.
Thus a::name is the proc for that method. Now, objects are also commands.
Placing it inside the namespace will create, well, the command a::name,
thus overriding the method.

I do agree that this is not perhaps the best of behaviours and not
expected. I'm not sure if child objects could be placed inside their own
'children' namespace. Uwe or Gustaf can probably comment on that.

One workaround is to create a 'children' child object yourself inside a.
Then place all the objects as children of it. The downside is that the
parent of those objects will now be an object called 'children'. The
parent of it will be 'a'.

                               / http://www.fishpool.com/~setok/
Received on Wed Nov 22 2006 - 15:48:54 CET

This archive was generated by hypermail 2.2.0 : Thu Nov 06 2008 - 11:10:48 CET