Re: [Flashcoders] [POLL] getters & setters preference
Initially I was wary of the built in get and set framework, but I came to really like this technique. For example, you want to update the score of your game, but doing so requires touching numerous gui elements and properties. Using the built in setter methodology allows you to abstract and simplify the API call. score ++; score += 10; score --; > On 4/26/06, Jim Tann <[EMAIL PROTECTED]> wrote: > > > > Hello all, > > > > After a long time of trying to figure which method of using getters & > > setters is better I though the best way to get a good answer is to throw > > it open to the list. > > > > Do you prefer to use the inbuilt getter & setter functionality? > > i.e. > > > > public function get myProperty():Number{ return _myProperty; } > > public function set myProperty(intSet:Number):Void{ _myProperty = > > intSet; } > > > > or do you prefer using normal functions? > > i.e. > > > > public function getMyProperty():Number{ return _myProperty; } > > public function setMyProperty(intSet:Number):Void{ _myProperty = intSet; > > } > > > > I like the first method as it looks cleaner, but there have been issues > > with inheritance where if you overwrite either the getter or setter, but > > not both in the child class it gets ignored. > > > > What are your views? > > Jim > > ___ > > Flashcoders@chattyfig.figleaf.com > > To change your subscription options or search the archive: > > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > > > Brought to you by Fig Leaf Software > > Premier Authorized Adobe Consulting and Training > > http://www.figleaf.com > > http://training.figleaf.com > > > ___ > Flashcoders@chattyfig.figleaf.com > To change your subscription options or search the archive: > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > Brought to you by Fig Leaf Software > Premier Authorized Adobe Consulting and Training > http://www.figleaf.com > http://training.figleaf.com > ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] [POLL] getters & setters preference
It's circumstancial, I have no preference. Depending on the problem, one will solve better than the other. However, which will solve a particular problem better is controversial. M. On 4/26/06, Jim Tann <[EMAIL PROTECTED]> wrote: > > Hello all, > > After a long time of trying to figure which method of using getters & > setters is better I though the best way to get a good answer is to throw > it open to the list. > > Do you prefer to use the inbuilt getter & setter functionality? > i.e. > > public function get myProperty():Number{ return _myProperty; } > public function set myProperty(intSet:Number):Void{ _myProperty = > intSet; } > > or do you prefer using normal functions? > i.e. > > public function getMyProperty():Number{ return _myProperty; } > public function setMyProperty(intSet:Number):Void{ _myProperty = intSet; > } > > I like the first method as it looks cleaner, but there have been issues > with inheritance where if you overwrite either the getter or setter, but > not both in the child class it gets ignored. > > What are your views? > Jim > ___ > Flashcoders@chattyfig.figleaf.com > To change your subscription options or search the archive: > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > Brought to you by Fig Leaf Software > Premier Authorized Adobe Consulting and Training > http://www.figleaf.com > http://training.figleaf.com > ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] [POLL] getters & setters preference
> The only other reason that I don't use built-in getters and setters is > that, at present, they don't work with Interfaces, only with Classes. > And we use Interfaces a lot. > > Ian Yes, that's a bit problematic. In haXe (http://haxe.org) all fields properties (public/private, getter/setter methods, readonly or writeonly) are also declarable and enforced in interfaces. Nicolas ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] [POLL] getters & setters preference
The only time built-in getter/setters really shine is with binding in Flex. You can bind to methods, but the runtime binding triggers change events for properties, and this allows you to all sorts of neat stuff under the hood to your GUI when a property changes. While you could bind to a getEnabled method vs. an enabled getter/setter property for example, you cannot run a setEnabled function when the value the enabled is binding to changes, but you can for the getter/setter. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] [POLL] getters & setters preference
The only other reason that I don't use built-in getters and setters is that, at present, they don't work with Interfaces, only with Classes. And we use Interfaces a lot. Ian On 4/26/06, Kevin Newman <[EMAIL PROTECTED]> wrote: > So in general, at this point I try to stay away from built in getters > and setters, and just use normal functions. It seems that if when you > set or get a property, if it is more than just getting or retrieving a > value, then there is no reason to hide those computations from the > programmer using the class. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] [POLL] getters & setters preference
I've wrestled with this question too. In general I've found that I usually only want to use a getter in situations where I don't want the user to be able to set the value. In this case, it has seemed more appropriate to just supply a getMyProperty value, so that it doesn't appear that the value can be set. In other cases, I provide only a way to set a specific value, and no way to read it (mostly because I want to do error checking on the value, and was too lazy to set up the get functions). In this case, using the built in method would seem more warranted, but then it is less obvious that the user of the class should catch an exception, or check to make sure the value was actually set properly. One other minor technical thing, is that you can't use Object.watch to watch for changes on a property that is a getter, which would rarely be used, but could still annoying for someone later on down the line, who has to discover this the hard way (like on javascript's window.location, grrr). So in general, at this point I try to stay away from built in getters and setters, and just use normal functions. It seems that if when you set or get a property, if it is more than just getting or retrieving a value, then there is no reason to hide those computations from the programmer using the class. Kevin N. Jim Tann wrote: Hello all, After a long time of trying to figure which method of using getters & setters is better I though the best way to get a good answer is to throw it open to the list. Do you prefer to use the inbuilt getter & setter functionality? i.e. public function get myProperty():Number{ return _myProperty; } public function set myProperty(intSet:Number):Void{ _myProperty = intSet; } or do you prefer using normal functions? i.e. public function getMyProperty():Number{ return _myProperty; } public function setMyProperty(intSet:Number):Void{ _myProperty = intSet; } I like the first method as it looks cleaner, but there have been issues with inheritance where if you overwrite either the getter or setter, but not both in the child class it gets ignored. What are your views? Jim ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] [POLL] getters & setters preference
I prefer the former. Using get and set is so much nicer. Besides, I do a lot of Exe based flash work, and being able to execute functions using variable assignment style expressions is a lifesaver. Lee -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jim Tann Sent: 26 April 2006 16:38 To: Flashcoders mailing list Subject: [Flashcoders] [POLL] getters & setters preference Hello all, After a long time of trying to figure which method of using getters & setters is better I though the best way to get a good answer is to throw it open to the list. Do you prefer to use the inbuilt getter & setter functionality? i.e. public function get myProperty():Number{ return _myProperty; } public function set myProperty(intSet:Number):Void{ _myProperty = intSet; } or do you prefer using normal functions? i.e. public function getMyProperty():Number{ return _myProperty; } public function setMyProperty(intSet:Number):Void{ _myProperty = intSet; } I like the first method as it looks cleaner, but there have been issues with inheritance where if you overwrite either the getter or setter, but not both in the child class it gets ignored. What are your views? Jim ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com