PDA

View Full Version : Proper use of setters/getters???



slopps
July 16th, 2007, 09:18 PM
Hey all,
Is it improper to put functionality other than setting or getting data in your getter/setter functions? I just wrote my Connector class ( http://www.kirupa.com/forum/showthread.php?t=268245) (http://www.kirupa.com/forum/showthread.php?t=268245) and for example, in my linethickness setter, I have:


public function set lineThickness(value:uint):void {
_lineThickness = value;
drawTriangle();
drawConnector();
}Is calling my draw methods in the setter improper? If so, what's the alternative?

CarlLooper
July 16th, 2007, 09:32 PM
If setting lineThickness is meant to also draw your triangle and connector then it's fine. Otherwise leave such out.

Carl

slopps
July 16th, 2007, 09:39 PM
Well, when a Connector is created, everything gets drawn upon initialization with the default linethickness, linecolor, etc. etc.
So when someone changes those, it needs to be redrawn w/ the new settings. I wasn't sure if I was supposed to make it broadcast an event for some other function to call the redrawing methods or something.
Once again, I'm still trying to understand events.

Thanks again Carl!

CarlLooper
July 16th, 2007, 09:55 PM
Nah - the coding for and runtime behaviour of an event broadcast (instead of an otherwise simple function call) would be less efficient - longer to code and slower performing.

Carl