On 29.11.2008, at 08:38, Michael A. Crawford wrote:
When implementing the MVC pattern, is it inappropriate or bad-form for views and layers to have direct read-only access to the model?
The Cocoa Fundamentals Guide discusses this topic, see Reference Library > Guides > Cocoa > Design Guidelines > Cocoa Fundamentals Guide > Cocoa Design Patterns > The Model-View-Controller Design Pattern > MVC as a Compound Design Pattern.
In figure 4-4 you can see, that in the traditional version of MVC models notify views and views get model states directly. In figure 4-5 you can see, that in the Cocoa version models and views communicate through mediating controllers only.
So: "is it inappropriate or bad-form ... ?" – generally no and Cocoa- wise yes, I think.
Klaus Begin forwarded message:
From: "Michael A. Crawford" <[EMAIL PROTECTED]> Date: November 28, 2008 11:38:12 PM PST To: cocoa-dev@lists.apple.com Subject: MVC questionWhen implementing the MVC pattern, is it inappropriate or bad-form for views and layers to have direct read-only access to the model?Currently I'm using KVO to have the different views and layers get notification of state changes in the model. Since the drawing of the views and layers is asynchronous to the processing of the KVO notifications, I'm cacheing local copies of the model's state in order to draw specific content based on said state. It seems that it would be more efficient to only handle the KVO notification as a trigger to redraw the view or layer using [layer setNeedsDisplay] and allow the individual layers to query the model directly.When the [layer drawInContext] method executes, if I have const or read-only access to the model, I don't need to have cached state information, instead I simply read the model state in question at the point of drawing and draw the appropriate content.What do the more experienced MVC/NSView/CALayer coder's think of this approach?More detail . . .In order to implement it, I need to change my layer hosting view so that instead of the view being the only one with a pointer to the model, I provide each layer and associated sub-layers with their own pointer to the model so that, upon observation of model state changes, the individual layers can query the model and draw.Currently, in the view's awakeFromNib method, I add all of my observers, passing the appropriate keys, contexts, and layers, and then allow the layers to handle the observation call-backs, caching the data associated with the keys being observed and calling their own drawInContext methods via [self setNeedsDisplay]. This requires duplication of model data.Is it worth duplicating this data in order to reduce coupling between the view and the model? I suspect not since the view is always going to be dependent on the model and any changes to the model will require changes to the view.-Michael ----------------------There are two ways of constructing a software design. One way is to make it so simple that there are obviously no deficiencies. And the other way is to make it so complicated that there are no obvious deficiencies.-- C.A.R. Hoare _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/michaelacrawford%40mac.com This email sent to [EMAIL PROTECTED]
-Michael ---------------------- The difference between genius and stupidity... ...is that genius has its limits." -- Albert Einstein
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]