I have a class (Wall) that inherits from Sprite.
Sprite already has width and height properties. But for wall, I need to do some other additional calculations when the properties change (f.e. make sure the new size won't cause it to overlap any other walls).
So, how do I set the width property inherited from the Sprite class from within the width setter of the Wall? (or perhaps there is an alternative way to do my bounds checking whenever width is set?)
public override function set width(w:Number):void {
//make sure it is a valid size
//if it is, then set the width of the *Sprite* to w. How?
}
Do the setter/getter methods always affect only values in objects where they are declared, even called from a subclass by inheritance? You cannot inherit the methods but not the variables. You inherit everything from the parent class. Private just means that you cannot directly access it, but it is still there.
You can always manually disable getter/setter generation for any field by using the special AccessLevel. NONE access level. This lets you override the behaviour of a @Getter , @Setter or @Data annotation on a class.
You may use lombok - to manually avoid getter and setter method. But it create by itself. The using of lombok significantly reduces a lot number of code.
super
is what you are looking for:
override public function set width(v:Number):void {
if(v > 100) {
super.width = v;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With