cocoa - OSX. Document & Window Controller design. How to interact with model -


i working on personal os x app, using cocoa, , have trouble designing interaction between document , window controller.

this summary of have far:

  • a document (nsdocument subclass), owns "model data", , in charge of loading, saving data from/to files, etc.
  • a window controller (nswindowcontroller subclass), attached document, creates window, , takes care "model data" displayed user.

now, question:

how window controller , document interact? more specifically: when event happens in view (e.g. user enters data), how window controller reaches model? see 2 options:

  1. the window controller takes care of updating data in model. seems straightforward, creates caos in how model accessed, since document 1 should manage model data.
  2. the window controller sends request document, , document takes care of updating model. keeps things more clear conceptually, implementation feels weird: window controller call document's "applychange:" method, , document perform "applychange:" on model; duplicating virtually going view model, since document act facade model, , window controller act facade of document... feels many facades!

i don't know do.

edited:

subclass of nsdocument is model controller (thanks correcting me).
more on that:nsdocument design perspective object in memory owns , manages document data.

enter image description here

to reach document window controller call @selector(document)

[self document]; //within windowcontroller subclass 

design:

you follow mvc pattern , other design patterns (mostly delegates , notifications). take @ lister app. if don't have access have uploaded github wonderful example (behind wall) shapeart app demo during wwdc 2013 (bringing ios apps os x).

maybe question more suitable move codereview


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -