Re: MVC Theory Help
Re: MVC Theory Help
- Subject: Re: MVC Theory Help
- From: Andy Lee <email@hidden>
- Date: Wed, 10 Jun 2009 23:49:31 -0400
On Jun 10, 2009, at 1:23 PM, Chunk 1978 wrote:
so i get View and understand Controller, but i'm a touch fuzzy on
Model.
does anyone have a simple way of explaining this? perhaps a clever
anecdote?
I thought this was pretty clever:
<http://www.youtube.com/watch?v=YYvOGPMLVDo>
My own off-the-cuff take on the subject:
The model is the information you present in the view. It is often an
abstraction of some real-world concept. Simple examples include
business concepts like Employee and mathematical concepts like
Rectangle. A typical view for displaying an Employee is a window
containing text fields for viewing or editing the employee's name,
social security number, salary, etc. A typical view for displaying a
Rectangle is, well, a window that draws a rectangle.
The model is kept separate from the view; it knows nothing about how
it is displayed. For one thing, this so-called "separation of
concerns" helps you write maintainable and reusable code. For another
thing, by keeping the model independent of the view, you can easily
display the same model different ways in different views. A common
example is any application with an inspector window -- it displays
information one way in your document window and another way in the
inspector. Look at how IB displays the frame rectangle of any given
view. It displays this information graphically in the view's window
(you can see where the view is located and how big it is) and
textually in the inspector (you can read the x, y, width, and
height). Same model information (a rectangle) displayed in two views.
Another example: imagine a chess game. In one view, it could be
displayed graphically on a picture of a chessboard. In another view,
it could be displayed textually in algebraic notation. In yet another
view, it could be displayed textually in descriptive notation. Same
underlying model -- a ChessGame class or some such -- with three
different presentations.
The controller acts as a liaison between the model and the view.
Sometimes the lines between model, view, and controller get fuzzy. It
happens. So we scratch our heads for a while and try to sort them out
as best we can.
--Andy
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden