Re: NSTableView philosophy question.. (MVC Pattern) where to put the dataSource delegate?
Re: NSTableView philosophy question.. (MVC Pattern) where to put the dataSource delegate?
- Subject: Re: NSTableView philosophy question.. (MVC Pattern) where to put the dataSource delegate?
- From: Bill Cheeseman <email@hidden>
- Date: Tue, 25 Jun 2002 15:42:14 -0400
on 02-06-25 12:13 PM, email@hidden at email@hidden wrote:
>
Anyway, I just added a table view and was wondering where is the
>
"appropriate" place to put the
>
NSTableView dataSource delegation methods?? My first inkling is the
>
appropriate NSWindowController sub-class
>
but I also was thinking maybe the NSDocument sub-class??
Here's my take on this very good question.
The data source delegate methods play the role of a controller, in MVC
terms. They take data from a model object (typically an array of records)
and display it in a view (the table). Going the other way, they take changes
the user enters in the view and synchronize the array. In other words, they
mediate between the view and the model. It's therefore convenient and
sensible to put these delegate methods in the window controller.
What about the array that holds the data? It is best placed in a model
object, I think. That way, it's likely to fit more easily into your routines
for saving the document's data to disk. There is nothing in the data source
delegate methods that requires the array to be located in any particular
place.
In the current version of Vermont Recipes (soon to be a Peachpit Press
book), this is how I do it. In fact, the data source delegate methods
associated with my table view switch between two different arrays under
control of a combo box setting. One of the arrays is located in the model
object, whence it gets saved to disk. The other is located in the window
controller because it contains a filtered subset of the full array. The
subset never has to be separately saved to disk because it is strictly for
display purposes, so it seems like it is part of the controller. The data
source methods don't care where either of these arrays are located, as long
as it can find them somewhere through the outlets available to it.
I find that "data source" is a misleading term. It tends to make people
think of the data itself, and some of the documentation refers to it that
way. But in Interface Builder, when you connect the "datasource" outlet, you
have to connect it to the object that holds the delegate methods, not to the
object that holds the data (which might or might not be the same object).
Think of the data source as a funnel, which is the source of the data in the
sense that the data pours out of the funnel into the view.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
The AppleScript Sourcebook -
http://www.AppleScriptSourcebook.com
Vermont Recipes -
http://www.stepwise.com/Articles/VermontRecipes
Croquet Club of Vermont -
http://members.valley.net/croquetvermont
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.