Minimalist Example of an MVC Pattern | 439
Note the overridden update( ) function in the CompositeView class shown in
Example 12-8. It calls the update method in all its children. Therefore, calling the
update( )function in the root node of the composite view structure will cascade
down and traverse the component tree updating all views. Let’s subclass
CompositeViewandComponentViewclasses and create a nested view structure to see
how this works.
Creating nested views
To illustrate nested views, we will create a composite view node and two child com-
ponent views as shown in Figure 12-2.
We will first create a composite view calledRootNodeView. This composite view will
receive keyboard input events from the stage. This view will also register to receive
aChildren.push(c);
}
override public function update(event:Event = null):void
{
for each (var c:ComponentView in aChildren)
{
c.update(event);
}
}
}
}
Figure 12-2. Nested view structure in minimalist example
Example 12-8. CompositeView.as (continued)
Model
Root node
registers to receive
update notices
RootNodeView
Update events
cascade down from
parent to child views
CharCodeLeafView ACIICharLeafView
Receives update
events from model
Nested views
Displays the
character code of
the key pressed
Displays the ASCII
character code of
the key pressed