
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
396
|
Chapter 18: The Model-View-Controller Design Pattern
Now that we have our view defined, let’s define the controller.
The Controller Implementation
Example 18-3 shows the Controller interface in our mvc package. The Controller
interface defines the basic services every Controller class must offer, namely:
• Methods to set and retrieve the view reference
• Methods to set and retrieve the model reference
In the Controller interface, references to the view must be instances of any class that
implements the View interface. References to the model must be instances of any
class that extends Observable.
* implementation for this method.
*/
public function update(o:Observable, infoObj:Object):Void {
}
}
Example 18-3. The Controller interface
import util.*;
import mvc.*;
/**
* Specifies the minimum services that the controller of
* a Model-View-Controller triad must provide.
*/
interface mvc.Controller {
/**
* Sets the model for this controller.
*/
public function setModel (m:Observable):Void;
/**
* Returns the model for this controller.
*/
public function getModel ( ):Observable;
/**
* Sets the view this controller is servicing.
*/
public function setView (v:View):Void;
/**
* Returns this controller's view.
*/
public function getView ( ):View;
}
Example 18-2. The AbstractView class (continued) ...