actionscript 3 - Override parent class instance variable in subclass -


in php it's trivial override properties of class in subclass. instance:

class generic_enemy {    protected $hp = 100;    protected $str = 5;     //...  }  class boss_enemy extends generic enemy {     protected $hp = 1000;     protected $str = 25; } 

which extremely convenient because at-a-glance can see in ways subclass differs parent class.

in as3 way i've found through getters, isn't elegant @ all:

public class genericenemy {    private var _hp:uint = 100;    private var _str:uint = 25;     public function hp():uint {       return _hp;    }     public function str():uint {       return _str;    } }  public class bossenemy extends genericenemy {    override public function hp():uint {       return 1000;    }     override public function str():uint {       return 25;    } } 

is there nicer way of doing aligns php approach?

specifically: let's i'm writing api let developer spin off own enemies. rather document have override hp , str properties rather explain have create new getter each property wish override. it's matter of trying create cleanest api , easiest document , maintain.

sometimes ya have write question in order see (obvious) answer:

public class genericenemy {    protected var _hp:uint = 100;    protected var _str:uint = 25;     public function genericenemy(){      //...    } }  public class bossenemy extends genericenemy {    public function bossenemy(){       _hp = 1000;       _str = 50;        super();    } } 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -