Chapter 3. Programming with Classes
Introduction
In this chapter
Understanding classes, objects, and types
Understanding encapsulation
Using packages
Understanding inheritance
Understanding polymorphism
Introducing methods and properties
Using statics
Understanding interfaces
Manipulating types
Programming using classes is essential to take advantage of the full power of ActionScript 3.0. By using classes, you participate in object‐oriented programming, a versatile way to think about and structure code. Objects are high‐level building blocks, and classes are the constructs which define them. In this chapter you learn what constitutes a class, how classes relate to objects and other language constructs, and how to write a class in ActionScript 3.0.
Understanding Classes
To program using classes, you must understand what classes are. Classes perform multiple roles in object‐oriented programming, and there are many ways to think about them. This section introduces these fundamental ideas.
Classes can model the real world
Classes often work best, and are easiest to think about, when they represent objects in the real world. You can, for example, create a class to represent a bicycle. That bicycle can have a color, a size, and two tires. You can pedal it, brake it, switch gears, and ring the bell. The bicycle has relationships with other real‐world objects: your feet, the road surface, occasionally a bike pump. If we model the bicycle as a class, we can represent all of these, and carefully design ...
Get ActionScript™ 3.0 Bible now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.