Re: avoiding spagetti code
Re: avoiding spagetti code
- Subject: Re: avoiding spagetti code
- From: Erik Price <email@hidden>
- Date: Tue, 10 Nov 2009 13:48:59 -0500
On Mon, Nov 9, 2009 at 5:04 PM, Oftenwrong Soong
<email@hidden> 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?
For sufficiently complex views, I sometimes find it useful to design a
"view model" that contains information specific to the display of the
data. For example, information about X/Y positions, distances between
different parts of a view, click counts, and measurements probably
don't belong anywhere in your business/data/domain model, but your
view will need to store this information somewhere both to read from
it and, occasionally, to write to it. Simpler views can just keep this
information within themselves as discrete instance variables, but when
this becomes unwieldy, using a structure like a view model can help
keep this data organized and even help you in conceptualizing what's
going on in your view.
e
_______________________________________________
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