Re: avoiding spagetti code
Re: avoiding spagetti code
- Subject: Re: avoiding spagetti code
- From: Jason Stephenson <email@hidden>
- Date: Mon, 09 Nov 2009 17:14:19 -0500
Oftenwrong Soong wrote:
Hi all,
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?
Have an actual controller class handle the interaction between the View
and the Model. Most of the MVC examples you find for Cocoa are actually
MC/V where model and controller are wrapped in 1 class. This is very
often easier to implement in a standalone application.
However, if you want real separation between the view and the model,
then you'll need a real controller class to query the model and pass
information to the view when the view needs the model data. The
controller could also do any transforms on the data required by the view.
In this way, the model doesn't have to know about the view, the view
doesn't have to know about the model, but the controller does know about
both.
HTH,
Jason
Thanks, Soong
_______________________________________________
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