User Guide
General coding conventions 73
Classes and objects
Class names are usually nouns or qualified nouns, beginning with an uppercase first letter. A
qualifier describes the noun or phrase. For example, instead of member, you might qualify the
noun using
NewMember or OldMember. Sometimes a class name is a compound word. Write class
names in mixed case beginning with an uppercase letter when the name includes concatenated
words. You do not have to pluralize the words you use in the class name, and, in most cases, it is
better to leave the words as qualified nouns.
Try to make the class name descriptive and simple, but most importantly, select a meaningful class
name. The name is descriptive of the class’s contents: do not be vague or misleading when you
name a class. Try to avoid acronyms and abbreviations unless they are more commonly used than
the long form (such as HTML), and remember that clear names are more important than short
names.
Do not use a class name in the properties of that class because it causes redundancy. For example,
it does not make sense to have
Cat.catWhiskers. Instead, Cat.whiskers is much better. Do not
use nouns that also might be interpreted as verbs, which might lead to confusion with methods,
states, or other application activities. Select meaningful, specific names rather than generic names.
See the following examples of class names for proper formatting:
class Widget;
class PlasticWidget;
class StreamingVideo;
It is a good practice to try and communicate the relationship a class has within a hierarchy when
you name it. This helps display its relationship within an application. For example, you might
have the
Widget interface, and the implementation of Widget might be PlasticWidget,
SteelWidget, and SmallWidget. For information on interfaces, see “Interfaces” on page 249.
For information on implementations, see
class in Flash ActionScript Language Reference.
You might have public and private member variables in a class. The class can contain variables
that you do not want users to set or access directly. Make these variables private and only allow
users to access the values using getter/setter methods. When naming member variables in your
class files, it is advisable and common practice to prefix the variable names with
m_. This helps
flag the variables as belonging to the class you’re creating, and generally makes the code more
readable.
Set most member variables to private unless there is a good reason for making them public. It is
much better from a design standpoint to make member variables private and allow access only to
those variables through a group of getter/setter functions. For more information on using private
and public member variables, see “Controlling member access” on page 256.
Packages
Put the prefix for a package name in all lowercase letters. Begin package names with
mx or
com.macromedia to maintain consistency when naming classes. The next parts of the package
name vary, depending on the particular naming scheme. For example, a convention might use
one of the following package names:
mx.containers.ScrollPane