ActionScript coding conventions 753
■ Don’t overuse getter/setter functions in your class file.
Getter/setter functions are excellent for a variety of purposes (see “About getter and setter
methods” on page 255), however overuse might indicate that you could improve upon
your application’s architecture or organization.
■ Set most member variables to private unless you have a good reason for making them
public.
From a design standpoint, it is much better to make member variables private and allow
access to those variables through a group of getter/setter functions only.
Using the this prefix in class files
Use the this keyword as a prefix within your classes for methods and member variables.
Although it is not necessary, it makes it easy to tell that a property or method belongs to a
class when it has a prefix; without it, you cannot tell if the property or method belongs to the
superclass.
You can also use a class name prefix for static variables and methods, even within a class. This
helps qualify the references you make. Qualifying references makes for readable code.
Depending on what coding environment you are using, your prefixes might also trigger code
completion and hinting. The following code demonstrates prefixing a static property with a
class name:
class Widget {
public static var widgetCount:Number = 0;
public function Widget() {
Widget.widgetCount++;
}
}
NOTE
You don’t have to add these prefixes, and some developers feel it is unnecessary.
Macromedia recommends that you add the
this keyword as a prefix, because it can
improve readability and it helps you write clean code by providing context.