View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide

Model-View-Controller Song

Uploaded Image: ModelViewController.jpg

MP3 (James Dempsey)


Lyrics by James Dempsey

Model View, Model View, Model View Controller
MVCís the paradigm for factoring your code,
into functional segments so your brain does not explode.
To achieve reusability you gotta keep those boundaries clean,
Model on the one side, View on the other, the Controllerís in between.

Model View - Itís got three layers like Oreos do.
Model View creamy Controller

Model objects represent your applications raison dítre.
Custom classes that contain data logic and et cetra.
You create custom classes in your appís problem domain,
then you can choose to reuse them with all the views,
but the model objects stay the same.

You can model a throttle in a manifold,
Model level two year old.
Model a bottle of fine Chardonnay.
Model all the twaddle stuff people say.
Model the coddle in a boiling eggs.
Model the waddle in Hexleyís legs.

One, two, three, four.
Model View - You can model all the models that pose for GQ.
Model View Controller

View objects tend to be controls that view and edit,
Cocoaís got a lot of those, well written to its credit.
Take an NSTextView, hand it any old Unicode string,
the user interacts with it, it can hold most anything.
But the view donít knows about the Model:
That string could be a phone number or the words of Aristotle.
Keep the coupling loose and so achieve a massive level of reuse.

Model View - All rendered very nicely in Aqua blue
Model View Controller

Youíre probably wondering now.
Youíre probably wondering how,
the data flows between Model and View.
The Controller has to mediate,
between each layerís changing state,
to synchronize the data of the two.
It pulls and pushes every changed value.

Model View - mad props to the smalltalk crew!
for Model View Controller

Model View - itís pronouced Oh Oh not Uh Uh
Model View Controller

Thereís a bit more on this story,
a few more miles upon this road,
well nobody seems to get much glory
writing controller code.
Well the model is mission critical
and gorgeous is the view,
But Iím not being lazy, but sometimes itís just crazy
how much code i write is just glue.
And it wouldnít be so tragic,
but the code ainít doing magic:
itís just moving values through.
And I wish I had a dime
for every single time
I set a TextFieldís stringValue.

Model View - how weíre gonna deep-six all that glue
Model View Controller

Controllerís know the Model and View very
uahh - intimately
They often are hardcoding
which is very verboten for reusability.
But now you can connect any value you select
to any view property.
And I think youíll start binding,
then youíll be finding less code in your source tree.
Yeah I know I was astounded,
thatís not even a rhyme.

But I think it bares repeating
all the code you wonít be needing,
when you hook it up in IB.

Model View - it even handles multiple selections too
Model View Controller

Model View - hope I get my G5 before you
Model View Controller

Yeah, yeah, yeah. Yeah.

Ralph Johnson'sComment

(squeak-dev mailing list - 17th july 2006)
The problem is that the song is NOT about Smalltalk MVC. In this song, the controller is a layer between the view and the model, which usually means it is a mediator. The song also says that the controller is copying values from one field to another, which also indicates that it is a mediator. However, in true MVC, the controller is a strategy for handling events. The events come directly to it, rather than to the view. The controller changes the model, but it is not notified by the model. When the user presses a key or moves the mouse, the controller receives the event. It checks with the view to map mouse locations into model coordinates, then interacts directly with the model. If it changes the model then the model notifies all dependents (observers), which notifes the view, which redisplays.

The song desribes Ivar Jacobson's Model/Interface/Control, in which the Control is responsible for an entire use case. It is not MVC. Jacobson's model is like the MVC model, but his Interface is a combination of View and Controller and his Control is not at all like
a real Controller.

Link to this Page