• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Design Question: Bindings & Custom Views
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Design Question: Bindings & Custom Views


  • Subject: Re: Design Question: Bindings & Custom Views
  • From: Negm-Awad Amin <email@hidden>
  • Date: Thu, 28 Aug 2008 10:35:16 +0200


Am Do,28.08.2008 um 10:15 schrieb Oleg Krupnov:

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.

This may be indeed a good idea to use categories for this purpose. Is it what everybody is using?

I have only one problem with this approach: As I mentioned before, I
need to add custom-view specific instance variables (states) to the
model object's category. The Objective-C categories do not allow
adding instance variables, only methods

I am considering to create a dictionary owned by the custom view,
containing state objects keyed by model object unique ID. This is a
kind of surrogate of subclassing the model objects inside the custom
view. I am not sure this is a good idea though. Are there other
approaches?
If I understood you correct, you think, that you fear a voilation of the MVC pattern. Correct?

Think about some points:
- sometimes the shape or something like this is a true part of the model. Think about predefined shapes and so on. So there is nothing wrong in storing that informtion in the model.
- Can you isolate the "shape-part" (model) from the drawing part (obviously depending on view states)?


Just an example: I had a graphic application that drawed some inserted shapes. The shape itself is a part of the model, the color of the shape, too. But when the user selects a shape (symbol), the color should change. So the drawing of the shape depends on a view property. I think, this is the core of your problem.

I solved it by returning only bezier paths and colors from the model. So the shape itself (model) is still a part of the model, but the drawing (depending on the view) is done inside the view. (Simply by stroking the paths.)

Cheers,
Amin


_______________________________________________

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

Amin Negm-Awad email@hidden




_______________________________________________

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


  • Follow-Ups:
    • Re: Design Question: Bindings & Custom Views
      • From: "Oleg Krupnov" <email@hidden>
References: 
 >Design Question: Bindings & Custom Views (From: "Oleg Krupnov" <email@hidden>)
 >Re: Design Question: Bindings & Custom Views (From: "Oleg Krupnov" <email@hidden>)

  • Prev by Date: Re: Design Question: Bindings & Custom Views
  • Next by Date: NSURLConnection and JavaScript
  • Previous by thread: Re: Design Question: Bindings & Custom Views
  • Next by thread: Re: Design Question: Bindings & Custom Views
  • Index(es):
    • Date
    • Thread