MVC question
MVC question
- Subject: MVC question
- From: "Michael A. Crawford" <email@hidden>
- Date: Fri, 28 Nov 2008 23:38:12 -0800
When 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
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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