FROM : John Brownlow
DATE : Mon Apr 04 22:28:51 2005
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
DATE : Mon Apr 04 22:28:51 2005
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
| Related mails | Author | Date |
|---|---|---|
| Keith Blount | Apr 4, 12:25 | |
| Johnny Deadman | Apr 4, 15:14 | |
| Keith Blount | Apr 4, 16:39 | |
| Serge Meynard | Apr 4, 16:58 | |
| Keith Blount | Apr 4, 18:33 | |
| John Brownlow | Apr 4, 22:28 | |
| Keith Blount | Apr 4, 23:18 |






Cocoa mail archive

