O'Reilly logo

ActionScript 3.0 Design Patterns by Chandima Cumaranatunge, William Sanders

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Key OOP Concepts Used with the Observer Pattern

One object-oriented design principle put forth in the original design pattern book by Gamma et al is to favor object composition over class inheritance. That is, when possible, design your programs using object composition instead of beginning with a superclass and then accomplishing reuse through inheritance. To understand the reason for this dictum, we need to look at object composition.

To appreciate the advantage of object composition over inheritance, we need to understand another principle put forth by Gamma, Helm, Johnson and Vlissides:

Program to an interface, not an implementation.

Let's first look at why programming to an interface is favored over programming to an implementation.

Choose the Interface

In a nutshell, according to Gamma et al, programming to an interface is better than programming to an implementation because it reduces implementation dependencies between subsystems. This increases software flexibility. As a result, changes can be made at runtime.

The idea of programming to an interface does not literally mean an ActionScript 3.0 construct interface as opposed to a class. That is, you can program to the interface of an abstract class or an interface instead of a class. What does that really mean, though?

The easiest way to understand this concept is to think of the methods in either an abstract class or interface as interfaces. An interface is a set of functions an object implements. Eric and Elisabeth Freeman ( ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required