Re: Design Question: Bindings & Custom Views
Re: Design Question: Bindings & Custom Views
- Subject: Re: Design Question: Bindings & Custom Views
- From: Paul Bruneau <email@hidden>
- Date: Wed, 27 Aug 2008 09:15:22 -0400
On Aug 27, 2008, at 8:10 AM, Oleg Krupnov wrote:
I am building a custom view that can display and edit some polymorphic
objects. Furthermore, the objects can be composite, i.e. contain child
objects hierarchically.
Now I want to bind this custom view to the model through a controller
(NSTreeController in my case).
In the examples I have seen (GraphicsBindings, Sketch), the custom
view, when it needs to draw objects or hit test objects or whatever
else, it queries the controller for the array of model objects and
sends them the corresponding message "draw", "hitTest" etc. defined in
the model interface. Is this actually the design everybody is using?
IMHO such design introduces an implicit dependency between the view
and the model. What if I want to have two or more views to view the
model objects? I would have to have drawInView1, drawInView2 etc.
messages in each model object's interface. Isn't it better to have the
draw and hitTest messages encapsulated in the custom view's interface
instead of the model objects (perhaps using the Visitor pattern to
account on the object polymorphism)? This is my first question.
Parts of your first question remind me of a situation that I had. Erik
Buck gave me some great advice and part of it was the following:
If you are worried about adding drawing code to a "Model" object,
add the drawing code in a category of <the model object>* and
maintain the category implementation in the "View" subsystem.
*I changed the words he used here because he used the name of my
specific class and I wanted to make it more readable in the general
case.
This will let you put a category into every view that you want to so
that your model objects get handled correctly for each view.
_______________________________________________
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