Get/set is useful when creating a visual object class, as well as for
setting private variables on set.  It's also useful when you don't want
the variable that is being set to be getted, as well.

For instance, I have an application which allows a user to type in the
day, month and year into three different fields.  

This data is applied to the model via setters:

        public function set month(n:Number):Void 
        {
                _month = --n;
                var d:Date = new Date(_msDate);
                d.setMonth(n);
                _msDate = d.getTime();
        }
        public function set day(n:Number):Void 
        {
                _day = n;
                var d:Date = new Date(_msDate);
                d.setDate(n);
                _msDate = d.getTime();
        }
        public function set year(n:Number):Void 
        {
                _year = n;
                if (String(_year).length == 1) {
                        _year = Number("200" + n);
                } else if (String(_year).length == 2) {
                        _year = Number("20" + n);
                }
                var d:Date = new Date(_msDate);
                d.setFullYear(_year);
                _msDate = d.getTime();
        }

This allows me to set the month to a valid flash month (month - 1), and
update _msDate, which is the date in milliseconds, for sorting by dates
very easily.

I use setters and getters because it makes autocompletion and code hints
a breeze.  It also is great for visual object model classes.

If you choose to write getVariable vs get variable, it's up to you.  I
use them in different ways at different times.
_______________________________________________
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

Reply via email to