Java Reference
In-Depth Information
the stack interface. The Adaptor pattern says to start with a container, such as an array,
and add an interface, such as the stack interface.
The Model-View-Controller Pattern
The Model-View-Controller pattern is a way of separating the I/O task of an application
from the rest of the application. The Model part of the pattern performs the heart of
the application. The View part is the output part; it displays a picture of the Model's
state. The Controller is the input part; it relays commands from the user to the Model.
Normally, each of the three interacting parts is realized as an object with responsibilities
for its own tasks. The Model-View-Controller pattern is an example of a divide-and-
conquer strategy. One big task is divided into three smaller tasks with well-defined
responsibilities. Display 12.4 gives a diagram of the Model-View-Controller pattern.
Note that the arrowheads are open. In UML, an open arrowhead indicates an association
where one object has a reference to another object of the type connected by the arrow.
As a very simple example, the Model might be a container class, such as an array. The
View might display one element of the array. The Controller gives commands to display
the element at a specified index. The Model (the array) notifies the View to display a
new element whenever the array contents change or a different index location is given.
Any application can be made to fit the Model-View-Controller pattern, but it is
particularly well suited to GUI (Graphical User Interface) design projects where the
View can indeed be a visualization of the state of the Model. (A GUI interface is simply
a windowing interface of the form you find in most modern software applications, as
opposed to the simple text I/O we have used so far in this topic.) For example, the Model
might be an object to represent your list of computer desktop object names. The View
could then be a GUI object that produces a screen display of your desktop icons. The
Controller relays commands to the Model (which is a desktop object) to add or delete
names. The Model object notifies the View object when the screen needs to be updated.
Model-View-
Controller
Display 12.4
Model-View-Controller Pattern
Model
data1
data2
.
.
.
Notify
action1()
action2()
.
.
.
Manipulate
View
Controller
...
...
update()
...
...
 
 
Search WWH ::




Custom Search