[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Moving towards a class system package proposal
- From: Mark Hamburg <mhamburg@...>
- Date: Sun, 23 Jan 2005 11:03:09 -0800
on 1/22/05 2:02 PM, PA at email@example.com wrote:
> Assuming an existing "description" method in the superclass one would
> like to extend, one could now invoke it like this:
> function MySubclass:description ()
> print "my very own description as well"
> Does this make any kind of sense?!?
Only if super is a local variable equal to the superclass. That's basically
the C++ solution -- i.e., explicitly specify the superclass in the upcall.
MySubclass = class( MyBaseClass )
local super = MyBaseClass
Now, I can feel free to write methods in MySubclass that reference super and
hence reference MyBaseClass provided that I write them in a context where
this definition of super is visible.
Of course, I could also just write them to explicitly mention MyBaseClass.
That becomes a maintenance issue, however, if I change the class hierarchy.
(I can do this in C++ as well by putting a typedef for super at the top of
My point was that the value of self was insufficient on its own to determine
the point in the class chain to start looking when making a call to the
inherited version of a method because self always starts at the end of the
chain and we would need to know how far we'd gotten in recursing through the
calls to inherited versions of the method.
P.S. Lua environment skankery (not actually recommended): Classes could
define a custom environment that they assign to each of their methods that
would include a definition of super.