-- Hear and forget; see and remember; do and understand...
the model-view-controller (MVC) design pattern
Just by breaking the program down into the three MVC components, one gains
many advantages. These are the most significant ones I've found through
my own experience:
Clarity of design : the public methods in the model
stand as an API for all the commands available to manipulate its data and
state. By glancing at the model's public method list, it should be easy to
understand how to control the model's behavior. When designing the
application, this trait makes the entire program easier to implement and
Efficient modularity of the design allows any of
the components to be swapped in and out as the user or programmer
desires - even the model! Changes to one aspect of the program aren't
coupled to other aspects, eliminating many nasty debugging situations.
Also, development of the various components can progress in parallel,
once the interface between the components is clearly defined.
Multiple views : the application can display the state
of the model in a variety of ways, and create/design them in a scalable,
modular way. This comes up in games, with a cockpit and a radar view, and
in my research applications, where I have a view to display the state of
the model and another view that collects data, calculates statistics, then
to saves the data to disk. Both views are using the same data, they just
use the information differently. During the development process, I usually
start out with a text based view, which just prints out the data that the
model is generating. Later, as I create new views, I can use the text
based view to verify the performance of the new views.
Ease of growth : controllers and views can grow as the
model grows; and older versions of the views and controllers can still be
used as long as a common interface is maintained (the text view just
mentioned is an example). For instance, if an application needs two types
of users, regular and administrator, they could use the same model, but
just have different controller and view implementations. This is related
to the similarity with the client/server architecture - where the new views
and servers are analogous to the clients.
Distributable : with a couple of proxies (another
design pattern - used in the snake
game) one can easily distribute any MVC application by only altering
the startup method of the application. Now, the application becomes a full
fledged set of client and server applications.
Powerful user interfaces : using the model's API, the
user interface can combine the method calls when presenting commands to the
user. Macros can be seen as a series of "standard" commands sent to the
model, all triggered by a single user action. This allows the program to
present the user with a cleaner, friendlier interface.