On Jan 19, 2009, at 12:57 PM, Paul Bruneau wrote:

I'm confused by it, since I have been directed in the past by people who know that The Cocoa Way is to have objects know how to draw themselves--via a category if desired.

Is there differing opinion on this? (apparently there is...)

This is tough to generalize. There is not only differing opinion, but also plenty of room for debate. :-)

In the Sketch example, there are different shapes (including "text"), each of which handles drawing somewhat differently. I suspect the decision not to put this into the canvas view is more a matter of organization than architecture. I happen to agree with the decision.

There's nothing about the MVC design pattern that demands all drawing code belongs in the view. In the particular case of a drawing application where the shapes to be drawn *are* the data model, how to draw a shape could be viewed as "business logic" for the model.

For the organizational argument, having a single view that includes the logic to draw every kind of shape (including those added in the future) seems messy and difficult to read / maintain. Stepping aside from API architecture and design patterns, we would logically expect a shape to be responsible for knowing how to represent itself. After all, the canvas merely hosts the shapes (however they're drawn) and provides UI interaction to manipulate them.

I'll remind everyone to consider my opening statement (hard to generalize) if it seems like I'm contradicting myself. :-)


I am going to be starting a large app that will have many assemblies and sub-assemblies that I want to draw. I had planned on the objects drawing themselves. Should I revisit my thinking?

If the assemblies and sub-assemblies are all homogenous (in that they all look more or less the same), I'd say yes, you should reconsider the Sketch-like approach.

For an extremely over-simplified example, consider a view that draws many labels. The shape, color, font, etc. of the labels are all the same; merely the text is different. In that case, I'd have the view be 100% responsible for all drawing.

  Just my opinion, not an edict. :-)

--
I.S.


_______________________________________________

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 arch...@mail-archive.com

Reply via email to