ActionScript 3.0 Design Patterns - Adobe

and Adobe Systems, Inc., is the authoritative resource for developers using Adobe technologies. ... Flash®, and Adobe Acrobat®. Get the latest news about ...
926KB Sizes 10 Downloads 147 Views
,title.3638 Page iii Tuesday, July 3, 2007 2:53 PM

ActionScript 3.0 Design Patterns

William B. Sanders and Chandima Cumaranatunge

Beijing • Cambridge • Farnham • Köln • Paris • Sebastopol • Taipei • Tokyo

,copyright.3756 Page iv Tuesday, July 3, 2007 2:53 PM

ActionScript 3.0 Design Patterns by William B. Sanders and Chandima Cumaranatunge Copyright © 2007 O’Reilly Media, Inc. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (safari.oreilly.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 or [email protected]

Editor: Steve Weiss Developmental Editor: Robyn G. Thomas Production Editor: Philip Dangler Copyeditor: Sohaila Abdulali

Indexer: John Bickelhaupt Cover Designer: Karen Montgomery Interior Designer: David Futato Illustrators: Robert Romano and Jessamyn Read

Printing History: July 20007:

First Edition.

Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. ActionScript 3.0 Design Patterns, the image of a rosy feather starfish, and related trade dress are trademarks of O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein.

This book uses RepKover™, a durable and flexible lay-flat binding. ISBN-10: 0-596-52846-9 ISBN-13: 978-0-59652846-1 [M]

Adobe Developer Library, a copublishing partnership between O’Reilly Media Inc., and Adobe Systems, Inc., is the authoritative resource for developers using Adobe technologies. These comprehensive resources offer learning solutions to help developers create cutting-edge interactive web applications that can reach virtually anyone on any platform. With top-quality books and innovative online resources covering the latest tools for rich-Internet application development, the Adobe Developer Library delivers expert training straight from the source. Topics include ActionScript, Adobe Flex®, Adobe Flash®, and Adobe Acrobat®. Get the latest news about books, online resources, and more at http://adobedeveloper library.com.

This excerpt is protected by copyright law. It is your responsibility to obtain permissions necessary for any proposed use of this material. Please direct your inquiries to [email protected]

,asdpTOC.fm.3994 Page vii Tuesday, July 3, 2007 2:53 PM

Table of Contents

Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi

Part I.

Constant Change

1. Object-Oriented Programming, Design Patterns, and ActionScript 3.0 . . . . . 3 The Pleasure of Doing Something Well OOP Basics Abstraction Encapsulation Inheritance Polymorphism Principles of Design Pattern Development Program to Interfaces over Implementations Favor Composition Maintenance and Extensibility Planning Your Application Plan: It Ain’t You Babe

3 10 11 15 24 34 42 45 49 57 60

Part II. Creational Patterns 2. Factory Method Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 What Is the Factory Method Pattern? Abstract Classes in ActionScript 3.0 Minimalist Example Hiding the Product Classes Example: Print Sh