Understanding Macromedia Flash 8 ActionScript 2: Basic Techniques for Creatives

Chapter 11: Inheritance and Polymorphism

Superclasses and Subclasses

Inheritance is what a person gets from his or her parents. In AS2 programming terms, inheritance is what a "subclass" gets from its "superclass". As discussed earlier in this book, classes provide a convenient way to group related methods and properties (functions and variables) together. But the real advantage of using classes is that one class can inherit the methods and properties of another. If a number of classes all need to share a core set of methods and properties then rather than define these methods and properties multiple times, they can be defined once in a superclass and then inherited by subclasses.

Fruit A Superclass

If inheritance is a new concept, then it may be helpful to think about it in familiar terms. The concept of class inheritance is actually familiar to everyone, but the terminology may not be. Take fruit, for example. The word "fruit" refers to a class of objects that are among other things edible. To adequately describe a fruit, a number of properties are required. Some (unscientific) fruit properties include:

  • color

  • juiciness

  • sweetness

These informal properties apply to all fruit: apples, oranges, bananas, grapes, etc. But apples have properties that bananas don't have, including:

  • roundness

  • sourness

And grapes have properties that neither apples, nor bananas have:

  • cluster size

  • translucence

The analogy can only go so far. Real fruit are more complex than any AS2 class will ever be, but the properties and relationships defined above can be described in...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Food Additives
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.