Re: MVC pattern, bindings, and controllers
Re: MVC pattern, bindings, and controllers
- Subject: Re: MVC pattern, bindings, and controllers
- From: Quincey Morris <email@hidden>
- Date: Mon, 6 Apr 2009 15:40:54 -0700
On Apr 6, 2009, at 09:30, Gwynne Raskind wrote:
This brings me to the "Attributed String" and "Data" bindings of
NSTextView itself. What it wants is either an
NS(Mutable?)AttributedString or an NSData containing RTF data. I
have neither of those in my model object; I have an NSMutableString
containing plain text data.
My understanding of the MVC pattern says that it would be an
unnaceptable leakage of UI code into the model if I provided methods
in the model object to return the data in those formats.
Incidentally, this is a misperception. There's nothing wrong with your
data model providing its data in multiple formats, because that in
itself does not require your data model to know anything about the
user interface. "Unacceptable leakage" would be keeping pointers to
view objects in your data model.
(However, there are some rare applications where it would make sense
for actual views to be kept in the data model. There's nothing
absolutely wrong with keeping any kind of data in the data model.
What's unacceptable is for the data model to be responsible for
maintaining the user interface itself.)
This brings me to the controller object, which is where such "glue"
code belongs. At the moment, I bind the views to the model using
NSObjectController. But NSObjectController doesn't provide the
functionality I need.
NSObjectController is probably the wrong controller, in this context.
If you have set up a data model, and window in a XIB/NIB file, then
*the* controller is the XIB File's Owner, which is likely a NSDocument
or a NSWindowController or the application delegate object, depending
on your application design. That would be the place to subclass and/or
add glue.
NSObjectController is actually a "mediating" controller, between the
File's Owner controller and view objects. In most cases, it does more
or less nothing, and exists mainly for consistency, to be the non-
array counterpart of NSArrayController. If you just want to bind a
text view to your data model, it makes very little difference whether
you bind directly to File's Owner or bind via a NSObjectController.
_______________________________________________
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