Re: MVC in Cocoa?
Re: MVC in Cocoa?
- Subject: Re: MVC in Cocoa?
- From: "Clark Cox" <email@hidden>
- Date: Mon, 24 Nov 2008 18:55:12 -0800
On Thu, Nov 20, 2008 at 4:13 PM, Michael Hines <email@hidden> wrote:
> Hey guys,
>
> This is my first message to the mailing list, so please let me know if
> I violate any form of etiquette. I apologize ahead of time.
>
> This is also my first Obj-C and Cocoa application.
>
> My application is basically a client for a text-protocol TCP server.
> If you are familiar with freechess.org, this is what I'm consuming.
>
> I want to have several views for the application. For example I want
> to have a login view, console view, a game board view, a chat view,
> etc.
>
> I have experience in Ruby on Rails, so I have an intuition that
> somehow I should implement models for Commands, Chats, Games, etc.,
> but I'm having trouble imagining how exactly this should be done.
>
> Specifically, who should own the connection?
Typically, the model itself should pretty dumb (i.e. set this
attribute, get this other attribute, load from file, save to file,
etc.)
The controller (or controllers) should be responsible for the "smarts"
(i.e. when the user does this, I tell the model to set these
attributes, when the view asks to draw that, I give it these
attributes from the model, etc.). The controllers are responsible for
managing the connections.
> How should it communicate with the models?
The model should be responsible for posting appropriate notifications
as its attributes are changed (quite trivial with Key Value
Notification).
The controller and view should listen for those notifications and take
action as appropriate
> How will the controllers get the same instances of the models?
If your application only has one model, then it can be a global
singleton, otherwise, the controller can be responsible for creating
the model when needed (remember, the controller should be responsible
for most of the "smarts").
> How can I have the views update dynamically when the models change?
Look into Key Value Coding, Key Value Observation, and Key Value
Binding. If your model is set up with accessor methods that follow the
normal Cocoa paradigms, then the notification happens as needed,
virtually automatically as the setters are called.
--
Clark S. Cox III
email@hidden
_______________________________________________
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
References: | |
| >MVC in Cocoa? (From: "Michael Hines" <email@hidden>) |