
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
OOP Quick Reference
|
317
Some OOP Tips
We’ve covered a lot of conceptual ground, so let’s synthesize some of these ideas to
help you put OOP into practice.
• Define everything in a class. All variables and functions should be properties and
methods of a class. This ensures that properties and methods are grouped logi-
cally and are always qualified by some object (which helps avoid scope prob-
lems).
• For the sake of organization and reuse across projects, store each class in a sin-
gle, separate .as text file.
• Define all classes on
_global.
• Use simulated namespaces. Create an object on
_global that will hold all your
classes, as shown in the next section, “OOP Application Template.”
• Create a single main( ) function that starts your application rolling.
• Create all instance methods on your constructor’s
prototype object, not in the
constructor.
• Always document your classes, properties, and methods. For an example, see the
next section, “OOP Application Template.” In your documentation, specify
which methods and properties are intended for public use and which are
intended for private, internal use by the class.
OOP Application Template
Sometimes ActionScript is so flexible that it becomes slippery. There are so many
ways to create a legal object-oriented application that finding a