FDT Template for Getter / Setter methods.
July 30th, 2008
If you’re being a good Flex / AS3 dev, you are probably wrapping your class member properties with public getter and setter methods.
If you’re not, you really, really should…
Getters and Setters, otherwise known as accessor methods, or mutator methods (among other things), are very helpful. They allow you to make your public properties have a far greater set of controls and features. I won’t go into all the details here, I’m assuming that you, like me, only fail to set them up because typing…
public var classMember : String;
Is slightly quicker than typing…
private var _classMember : String;
public function set classMember( value : String ) : void {
_classMember = value;
}
public function get classMember( ) : String {
return _classMember;
}
Anyway, if you are an FDT user, (or your chosen IDE has a templating feature) you can create a template to do this for you.
Read/Write member … (template name member)
private var _${name} : ${type};
public function set ${name}( value : ${type} ) : void {
_${name} = value;
}
public function get ${name}( ) : ${type} {
return _${name};
}
And then it will only take as long as setting up a public var, but with all the goodness that comes with using getter/setters…
You could setup templates for a read only member, and a write only member too…
Read only member … (template name rmember)
private var _${name} : ${type};
public function get ${name}( ) : ${type} {
return _${name};
}
Write only member … (template name wmember)
private var _${name} : ${type};
public function set ${name}( value : ${type} ) : void {
_${name} = value;
}
Download the FDT template file.
can you Digg it?
is it del.icio.us? 
Category: General



Leave a Comment
You must be logged in to post a comment .
Trackback this post | Subscribe to the comments via RSS Feed