[Xotcl] Dynamic dispatch and subclasses

Neil Madden nem at cs.nott.ac.uk
Wed May 19 19:30:04 CEST 2004

Hello all,

Just noticed the following behaviour in XOTcl:

Class Base
Base instproc foo {} {
     puts "Foo in Base"
Base instproc bar {} {
     # Just call foo
     my foo
Class Sub -superclass Base
Sub instproc foo {} {
     puts "Foo in Sub"
(Desktop) 56 % Sub a
(Desktop) 57 % a foo
Foo in Sub
(Desktop) 58 % a bar
Foo in Sub

I was kind of expecting the last to say "Foo in Base", as the method 
call of "foo" was dispatched from the Base class level. This is an 
interesting problem, as I can see reasons why you might want to do the 
current behaviour. However, I'm worried about some of the implications 
of implementation details and name clashes. Suppose I implement some 
class Base, which as part of it's implementation has a (private) method 
DoStuff. Now suppose someone else sub-classes my class, and in their 
implementation, they also happen to have a DoStuff method - this is 
going to break my implementation. It seems like this is breaking 
encapsulation somewhat. It seems like the cases where this dynamic 
dispatch could be useful could also be solved by passing in an explicit 
callback - that way you aren't relying on an implementation detail.

Am I missing a good reason for this? My OO theory is perhaps lacking in 
this area. I can see that I can get around it easily by prefixing my 
private methods:

Base instproc BaseDoStuff {...} { ... }

but this seems a bit ugly (reminds me of pre-namespace Tcl). Does XOTcl 
have some other cool feature that I'm missing.



More information about the Xotcl mailing list