224 | Chapter 6: Composite Pattern
The Composite class shown in Example 6-12 extends theComponentclass and over-
rides theupdate( ) method.
Example 6-11. Component.as
package
{
import flash.errors.IllegalOperationError;
import flash.display.Sprite;
// ABSTRACT Class (should be subclassed and not instantiated)
public class Component extends Sprite
{
protected var parentNode:Composite = null;
public function add(c:Component):void
{
throw new IllegalOperationError(
"add operation not supported");
}
public function remove(c:Component):void
{
throw new IllegalOperationError(
"remove operation not supported");
}
public function getChild(n:int):Component
{
throw new IllegalOperationError(
"getChild operation not supported");
return null;
}
// ABSTRACT Method (must be overridden in a subclass)
public function update( ):void {}
internal function setParent(aParent:Composite):void
{
parentNode = aParent;
}
public function getParent( ):Composite
{
return parentNode;
}
}
}