Skip to Main Content
Essential ActionScript 3.0
book

Essential ActionScript 3.0

by Colin Moock
June 2007
Intermediate to advanced content levelIntermediate to advanced
948 pages
27h 2m
English
O'Reilly Media, Inc.
Content preview from Essential ActionScript 3.0

Chapter 6. Inheritance

In object-oriented programming, inheritance is a formal relationship between two or more classes, wherein one class borrows (or inherits) the variable and method definitions of another class. In the practical, technical sense, inheritance simply lets one class use the code in another class.

But the term inheritance implies much more than code reuse. Inheritance is as much an intellectual tool as it is a technical tool. It lets programmers conceptualize a group of classes in hierarchical terms. In biology, inheritance is a genetic process through which one living creature passes on traits to another. You are said to have inherited your mother’s eyes or your father’s nose, even though you don’t look exactly like either of your parents. In object-oriented programming, inheritance has a similar connotation. It lets a class look and feel in many ways like another class, while adding its own unique features.

This chapter begins by examining the syntax and general use of inheritance. Once we understand inheritance on a practical level, we’ll consider its benefits and alternatives. Finally, we’ll apply inheritance to our virtual zoo program.

A Primer on Inheritance

Let’s consider a very simple, abstract example to get a feel for how inheritance works (we’ll get into practical applications once we cover the basic syntax). Here’s a class named A, with a single instance method, m( ), and a single instance variable, v:

public class A { public var v = 10; public function m ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Essential ActionScript 2.0

Essential ActionScript 2.0

Colin Moock
The ActionScript 3.0 Quick Reference Guide

The ActionScript 3.0 Quick Reference Guide

Jen deHaan, David Stiller, Darren Richardson, Rich Shupe
ActionScript 3.0 Cookbook

ActionScript 3.0 Cookbook

Joey Lott, Darron Schall, Keith Peters

Publisher Resources

ISBN: 0596526946Errata