• 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: avoiding spagetti code
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: avoiding spagetti code


  • Subject: Re: avoiding spagetti code
  • From: Rob Keniger <email@hidden>
  • Date: Tue, 10 Nov 2009 09:25:09 +1000

On 10/11/2009, at 8:04 AM, Oftenwrong Soong wrote:

> In the MVC style, I want to avoid connecting directly between a view and a model. However I have a custom NSView subclass that renders a graphical view of the model and therefore it needs information from the model. I think it is considered bad practice to put a pointer to the model directly in my NSView subclass. However how can this type of coupling be avoided if the view needs the information?


I struggled with this for a while, but you just need to look at some of the built-in complex views to see how this can be done.

In particular, have a look at the datasource and delegate methods for NSTableView, for instance. The view publishes protocols which a controller object can use to control how the view is displayed. You can do exactly the same thing for your own custom view.

You use the controller object to supply the view with the information that it needs to be able to draw representations of your model objects.

--
Rob Keniger



_______________________________________________

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: 
 >avoiding spagetti code (From: Oftenwrong Soong <email@hidden>)

  • Prev by Date: Re: Trouble with initial position of NSScrollView
  • Next by Date: Re: Cocoa Sounds
  • Previous by thread: Re: avoiding spagetti code
  • Next by thread: Re: avoiding spagetti code
  • Index(es):
    • Date
    • Thread