In the classic 'Sundae extends Vanilla with Banana' example,
all of the classes define function 'test'. Just focusing on this part,
I was a little confounded by the need for override and public keywords.
What follows is a recipe that works, and it does make sense.
'public' and 'override' must appear exactly as indicated:
class Vanilla {
public function test () { return "vanilla"; }
}
interface Banana {
function test () ;
}
class Banana$Vanilla extends Vanilla implements Banana {
public override function test () { return "banana"; }
}
class Sundae extends Banana$Vanilla {
public override function test () { return "sundae"); }
}
In Banana$Vanilla:test, the 'public' is needed satisfy
the 'implements Banana'. The 'override' is needed since
test is also defined in Vanilla.
In Sundae:test, 'override' is needed because test is defined in
superclasses. 'public' is needed to match Banana$Vanilla.
In Vanilla:test, the 'public' is needed to match what is being
overridden in Banana$Vanilla.
So back up to what the original source must look like:
class Vanilla {
public function test () { return "vanilla"; }
}
mixin Banana {
/*public?*/ override function test () { return "banana"; }
}
class Sundae with Banana {
public override function test () { return "sundae"); }
}
Should we require 'public' on the mixin? or is it optional?
(It actually doesn't matter much to me -- I think I always emit
public in the class, and no public in the interface).
Obviously if you know that the ultimate superclass has test(),
then the mixin should declare it override. Is this something
we'll know in practice? In theory this could be detected
for the classes we see in the parse, but it's a bigger deal
if the method being overridden is in a library (eventually).
Also, I was wondering how namespaces work in this.
From some quick experiments, it looks like namespaces
are not allowed on interface methods,
interface Banana {
// ns1 function another(); // XXX compiler error
function another();
}
nor by using a namespace name can you fulfill your implementation:
class Banana$Vanilla extends Vanilla implements Banana {
ns1 function another(); // XXX error - Banana not
implemented.
}
- Don
--
Don Anderson
Java/C/C++, Berkeley DB, systems consultant
voice: 617-547-7881
email: [EMAIL PROTECTED]
www: http://www.ddanderson.com