[haXe] Abstract Classes?
Nicolas Cannasse
ncannasse at motion-twin.com
Wed Dec 13 18:03:38 CET 2006
> This turns out not to be all that useful:
>
> A.hx:
> --------------
> class A {
> private var aApi:AApi;
>
> private function new (aApi:AApi) {
> this.aApi = aApi;
> }
>
> public function foo () {
> aApi.bar(); // cannot access to private field bar
> }
> }
>
> typedef AApi = {
> private function bar ():Void;
> }
> ---------
> B.hx:
> ---------
> class B extends A {
> public function new () {
> super(this);
> }
>
> private function bar ():Void {
> trace("bar");
> }
> }
> --------
> Main.hx:
> --------
> class Main {
> public static main ():Void {
> var b:B = new B();
> b.foo();
> }
> }
> --------
>
> A.hx fails to compile, since access to the private function in the
> typedef doesn't seem to be allowed, even from the same file. This
> looks like a bug?
Not exactly, it actually makes perfect sense considering the
relationship between A and AApi. This way of implementing abstract
classes don't allow private abstract metods, and I don't see an answer
to that.
Nicolas
More information about the Haxe
mailing list