• 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: MVC view/controller separation question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: MVC view/controller separation question


  • Subject: Re: MVC view/controller separation question
  • From: John Brownlow <email@hidden>
  • Date: Mon, 4 Apr 2005 16:28:51 -0400

Keith -- you rightly sense that this is not quite the right way to do it.

The thing to do is to treat the textView purely as a view object... an interface between the user and your app's logic.

It is your NSDocument's job, or a separate controller class, to set up the infrastructure of notes, note manager, textView etcetera.

I sometimes think of this in military terms... the controllers are the officers, the views are the infantry, and the models are the quartermasters.

In this context, the NSDocument is like the General, the textView is a sergeant major, and the textStorage is the quartermaster. Your NotesManager is a Lieutenant, which is why Sgt. TextView shouldn't be ordering it around.

It is possible for the infantry to have very demanding jobs but they still have to follow orders. If they want to make decisions which appear to be beyond their remit, they should send polite notifications and delegate messages. "Sgt. TextView requesting permission to insert a newline, sir". "Please may I have the text of the document which was stored on disk, sir?"

Of course it's a silly analogy, but if you find that your General is interacting with the enemy (the user!) or that your infantry are performing quartermaster duties (load & save) rather than fighting the enemy (interacting with the user), or that your quartermaster is fighting the enemy, or that your generals are being commissioned by your corporals, the structure of your army needs looking at...

The other good thing about this analogy is that lower-ranking soldiers should operate on a need-to-know basis... so Sgt. Textview should know nothing about Private Note except that he reported for duty on the orders of Lt. NoteManager, who was commissioned by Gen. NSDocument.

Sorry, enough.



On Apr 4, 2005, at 12:33 PM, Keith Blount wrote:

The text view will set up an instance of a
NotesManager controller object when it is initiated.
This notes manager will observe all changes to the
notes and send notifications accordingly, so that the
margin and text views know when to update. This way,
text views will be able to share notes managers if
they share text storage (to keep two views in sync,
for instance).

The text view can then just send the notes manager a
method such as
updateNoteRangesUsingAffectedCharRange:replacementString:
or something similar, or just post a notification with
this information. The text view will have to
communicate with the notes manager directly no matter
what, as its contextual menu will have the option to
add a note etc...

Hopefully this is at least a little more MVC friendly,
although it does still rely on a view creating and
calling methods on a controller rather than the other
way around, which does seem backward...
--
John Brownlow
Deep Fried Films, Inc

http://www.johnbrownlow.com
http://www.pinkheadedbug.com

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: MVC view/controller separation question (From: Keith Blount <email@hidden>)

  • Prev by Date: Re: insertObject:in<Key>AtIndex: not being called.
  • Next by Date: vm_allocate errors
  • Previous by thread: Re: MVC view/controller separation question
  • Next by thread: Re: MVC view/controller separation question
  • Index(es):
    • Date
    • Thread