[haXe] Abstract Classes?

Nicolas Cannasse ncannasse at motion-twin.com
Mon Nov 6 16:05:23 CET 2006


> Yeah, exactly. Isn't Abstract Classes a perfectly good OO concept?
> 
> Is it a low priority feature, or is it not considered to be implemented at  
> all?
> 
> / Rickard

Abstract classes can be implemented by using an API parameter :

typedef UserApi = {
    function getName() : String;
    function getText() : String;
}

class AbstractUser {

   var api : UserApi;

   public function new( api : UserApi ) {
        this.api = api;
   }

   public function say() {
        trace(api.getName()+" says "+api.getText());
   }

}

------------------------

class UserImpl extends AbstractUser {

    public function new() {
        super(this);
    }

    public function getName() : String {
        return "Me";
    }

    public function getText() : String {
        return "Hello";
    }

}

-------------------

The good point is that the abstract interface is separate from the class
body, so you don't have to extends AbstractUser to define an User
interface. This can be especially interesting since your User API can be
used with several abstract classes and not only one.

Nicolas




More information about the Haxe mailing list