+1 :-)
Use public methods when it's a method, public properties when it's a property.
Simple as that..
explicit should only be used for internal things to work, usually called by an
implicit setter:
private var _data:Object;
private function setData():void {
// do stuff with _data
}
public function set data(value:Object):void {
_data = value;
setData();
}
And a *big* +1 for this:
That being said, I don't abide by the retarded rule that you shouldn't have
public vars in a class.
regards,
Muzak
----- Original Message -----
From: "Steven Sacks" <[EMAIL PROTECTED]>
To: "Flash Coders List" <[email protected]>
Sent: Wednesday, December 10, 2008 5:01 AM
Subject: Re: [Flashcoders] use get / set functions or make your own
For clarity, they're referred to as implicit and explicit.
get prop / set prop = implicit
getProp() / setProp = explicit
In AS2, it made a difference because implicits were available right away,
whereas explicits were not available for 1 frame. This limitation is not
present in AS3.
Basically, implicit implies properties of a class, whereas explicit implies
methods of a class.
I opt for implicit over explicit because this:
foo.prop = value;
makes more sense than
foo.setProp(value);
I leave methods for methods, not properties.
That being said, I don't abide by the retarded rule that you shouldn't have
public vars in a class. People who do this
private var _foo:Boolean;
public function get foo():Boolean { return _foo; }
public function set foo(value:Boolean):void { _foo = value; }
are masturbating and I'm not impressed by their bloated ego...I mean code. ;)
Unless something needs to happen immediately within the class when you set or
get a prop (i.e. a state change), it's fine for it to be a public var. It's
faster, it's less bloat and most of us aren't writing large applications with a
bunch of other developers. Some of these rules were created for when good
coders are forced to work with bad coders and the good ones need to protect
their code from the bad ones. When it's just you and a couple other devs, and
you're all competent, you don't need all these checks and balances that are
nothing more than compensation for people who you wish you didn't have to code
with. /rant ;)
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders