• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: MVC in Cocoa?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: MVC in Cocoa?


  • Subject: Re: MVC in Cocoa?
  • From: David Casseres <email@hidden>
  • Date: Tue, 25 Nov 2008 09:48:59 -0800

It's worth mentioning that MVC can be "recursive." For example, in the app I work on, the most global MVC design is that the model is an sqLite database, and the controller is the "data manager," code that keeps the model up to date and presents an API for access to information that it extracts from the model. The view is the user interface. a client of the data controller's API.

But from within the UI code, it looks like the data controller's API is the model. The controller is a bunch of logic used by various screens, contained in the application delegate object, and the view is the collection of screens presented by the application.

Finally, at the Cocoa level, each screen consists of a View that is a Cocoa view class, with its own Cocoa controller object, and the model is data obtained from the API of the application delegate and a few other associated objects.
I guess to be a total Cocoa head, I'd be using Core Data in there somewhere.


On Nov 24, 2008, at 6:55 PM, Clark Cox wrote:

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

_______________________________________________

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>)
 >Re: MVC in Cocoa? (From: "Clark Cox" <email@hidden>)

  • Prev by Date: awakeFromNib is not called in Tiger [PPC], but called in Leopard [Intel]
  • Next by Date: Re: Killing a Thread
  • Previous by thread: Re: MVC in Cocoa?
  • Next by thread: in NSTextView :Attributes of pasted Text different from original Text
  • Index(es):
    • Date
    • Thread