• 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: A question on MVC design
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A question on MVC design


  • Subject: Re: A question on MVC design
  • From: Steve Sims <email@hidden>
  • Date: Mon, 17 May 2004 08:34:15 -0400

On 16 May 2004, at 21:58, Adam wrote:

I am designing a game that plays over the internet. The classes I have so far are:

A view class to draw the state of the game
A model class to represent the state of the game
A controller class

I also have a socket stream class that is capable of sending and receiving commands to and from a server. I am not sure where this fits into the MVC design. Is it any of them?

Also, the model needs to update itself based on info the socket receives.

The controller needs to send commands to the server through the socket,

OK, as you describe it here it sounds like your socket stream class is a controller object, a peer of the "controller class" you mention. Just as it's OK to have multiple views on your data it's also OK to have multiple controllers in MVC dealing with a single model. It's also OK to have multiple models - indeed that might be useful to keep track of stream-related data.

When you have multiple controller classes I find it's usually best to limit their functionality to dealing with a particular area. In this case it sounds like you're talking about a comms controller as well as a UI controller. If you mix the two it can get rather confusing working out which objects are responsible for what and where you need to make changes.

You might want to consider further abstracting your communications into two objects, with a game comms controller as well as your stream class. This would make your stream class more general and easier to reuse in other apps. Also it would mean that you could potentially support other comms options, e.g. bluetooth for local comms as well as internet for remote.

What is the best way for these 3 to communicate with each other? Messaging, instances of each-other other all over the place, is there a best way?

That I can't really tell you - you're going to have to work it out for yourself. Remember though that Interface Builder is your friend, and setting up outlets and instances of your objects inside IB can make sure that your objects all know about each other when your app starts up. If you need your controllers to know about each other as well as your data model just have outlets and connect them up.

Steve
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >A question on MVC design (From: Adam <email@hidden>)

  • Prev by Date: [ANN] Anthracite Web Mining Desktop v1.0
  • Next by Date: Controlling where a tooltip will be displayed
  • Previous by thread: A question on MVC design
  • Next by thread: Pinning to arbitrary NSSlider values
  • Index(es):
    • Date
    • Thread