
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
The Duality of MovieClip Subclasses
|
317
Do Box instances need all the features of MovieClip instances? Do they need to be
dragged with the mouse? No. Do they need to be able to create text fields? No.
Should we be able to check the number of bytes loaded by a Box instance? Or set the
mask over a box? No and no. None of these features are immediate requirements of
the Box class. Furthermore, a Box instance doesn’t need a timeline or the timeline
control methods of the MovieClip class. It doesn’t seem as if a Box “Is-A” MovieClip.
In fact, a Box more likely “Is-A” Shape! If, in a larger application, we made the Box
class a MovieClip subclass, then it wouldn’t be able to inherit from a more natural
superclass, such as Shape. Our original composition-based design was probably the
better choice.
The warning here is a refrain from Chapter 6—don’t inherit from a class just to bor-
row some of its functionality; make sure the “Is-A” relationship exists before extend-
ing a class. If you’re creating a new kind of generic multimedia class that uses most
or all of the features of MovieClip, by all means subclass MovieClip. (The Flash UI
Components fall into that category.) But if you’re just trying to draw something to
the screen, make sure you prudently consider composition before opting for