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

[Xotcl] Suggestion for class redefinition logic

From: Kristoffer Lawson <setok_at_fishpool.com>
Date: Wed, 10 Jan 2001 00:23:56 +0200 (EET)

A couple of times I've come across a feature in XOTcl that makes it
more difficult for me to structure my applications the way I would like.

First I'll explain the structure I'd like:

In file foo.tcl I have class A defined. foo.tcl also sources the file
bar.tcl, which defines classes B and C, which are sub-classes of A.
I source bar.tcl at the top of foo.tcl because that's where I tend to put
things like that (as I would in C).

The problem:

I get an error when sourcing bar.tcl because classes B and C depend on
class A, which is only later defined in file foo.tcl. That's
understandable, so I build another file, definitions.tcl. In there I put
a stub for class A, with no methods defined yet. The methods are still
defined in foo.tcl.

The problem with this is that I like to have the "Class A" line in foo.tcl
as well, near the methods and the _at_ documentation. Just to remind me and
to keep things together nicely -- and so that the class definitions by
themselves don't need an external file. Now, the class that B and C point
to is still the one defined in definitions.tcl, and even though class A is
essentially redefined in foo.tcl, B and C do not point to this class, but
the one with no methods.

Now, there are ways around this, of course. In fact, it could be argued
that when this situation occurs the program perhaps should be restructured
somehow anyway. OTOH, maybe not. So would it be worth considering the
option that if a class is redefined then either it directly redefines
the existing class (ie. the class definition line is ignored), or it
makes all references to the original class point to the redefined one.
Are there good arguments against this behaviour?

         - ---------- = = ---------//--+
         | / Kristoffer Lawson | www.fishpool.fi|.com
         +-> | setok_at_fishpool.com | - - --+------
             |-- Fishpool Creations Ltd - / |
             +-------- = - - - = --------- /~setok/