740 Best Practices and Coding Conventions for ActionScript 2.0
The following guidelines apply to naming classes:
■ Begin a class name with an uppercase letter.
■ Write class names in mixed case when it’s a compound or concatenated word.
Begin with an uppercase letter for a compound or concatenated word. A good example is
NewMember.
■ Class names are usually nouns or qualified nouns.
A qualifier describes the noun or phrase. For example, instead of “member,” you might
qualify the noun by using
NewMember or OldMember.
■ Clear names are more important than short names.
■ Don’t use acronyms and abbreviations.
The exception to this rule is if acronyms or abbreviations represent the standard way to
use a term (such as HTML or CFM). For commonly used acronyms, use mixed cases such
as
NewHtmlParser instead of NewHTMLParser for improved readability.
■ Use meaningful and simple names that are descriptive of the class contents.
To avoid being vague or misleading, use generic names.
■ Sometimes a class name is a compound word.
A qualifier might describe the noun or phrase. For example, instead of “member,” you
might qualify the noun using
NewMember or OldMember.
■ Do not pluralize the words you use in the class name (such as Witches or BaldPirates).
In most cases, it is better to leave the words as qualified nouns instead. A qualifier
describes the noun or phrase. For example, instead of “cat” or “buckaneer,” you might
qualify the noun by using
BlackCat or OldBuckaneer.
■ Don’t 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.
■ Don’t use nouns that also might be interpreted as verbs.
For example,
Running, or Gardening. Using these nouns might lead to confusion with
methods, states, or other application activities.
■ Use unique class names for each class in a single application.
■ Do not name classes so that they conflict with the names of built-in classes in Flash.
■ Try to communicate the relationship that a class has within a hierarchy.
This helps display a class’s 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 Chapter 9, “Interfaces.”