AS getters and setters, hope this doesn't make me a n00b

I swear I do Flex for a living. For 20 months now it's just Flex, Flex, and Flex. Yet it was just last week that I first used a setter function in an MXML component.

Before:

IN Scorecard.mxml:

private var _scorecardID:String = '';
public function init(scorecardid:String):void{
   this._scorecardID = scorecardid;
   ro.getScorecard(this._scorecardID);
}

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

IN THE CALLING COMPONENT:

var s:Scorecard = new Scorecard();
s.init('123abc');
/* add s to the visual layout of the screen */

After:

IN Scorecard.mxml:

private var _scorecardID:String = '';
public function set ScorecardID(scorecardid:String):void{
   this._scorecardID = scorecardid;
   ro.getScorecard(this._scorecardID);
}

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

IN THE CALLING COMPONENT:

var s:Scorecard = new Scorecard();
s.ScorecardID = '123abc';
/* add s to the visual layout of the screen */

Difference? Not a ton. I'm still exploring all the pros and cons. Sure, there are a million blog posts out there I'm sure, but I want to make my own mistakes! Both have the variable private, that's good. But I think using the setter is a little more intuitive and supports a better model of development. I could put some validation and other goodies into the setter function before calling the RemoteObject. Using the setter function ensures that validation and goodies are run when the value is changed. Bit nicer than remembering to run it through the init() (or whatev) function.

Ooo! How do I do

var s:Scorecard = new Scorecard('123abc');
that would be sweet.

Comments
BlogCFC was created by Raymond Camden. This blog is running version 5.9.002. Contact Blog Owner