Re: Where to put dataSource routines
Re: Where to put dataSource routines
- Subject: Re: Where to put dataSource routines
- From: Bill Cheeseman <email@hidden>
- Date: Thu, 25 Apr 2002 07:14:23 -0400
on 02-04-24 11:31 PM, Mike O'Connor at email@hidden wrote:
>
This is a program architecture question. I'm new to Cocoa. I've got a
>
document whose window contains an outlineView. I'm trying to be true to the
>
model-view-controller concept. So, I'm trying to figure out where to put the
>
dataSource methods. They seem like controller functions since they move data
>
between the model and a view, but they seem like data functions since they
>
are strictly ways to access data in the model.
>
>
My app is document based. The document data is represented by one data
>
object, which is the root of a tree of data. There is an AppController, but
>
the controller stuff for the document is in the MyDocument class. So the
>
choice seems to be between putting the dataSource methods either in the data
>
object class, or the controlling document class.
>
>
The reason I'm torn is it seems like it should be in the controller, but if
>
I do that, I'd put them there and probably write virtually the same methods
>
in the data object and the controller routines would be a cover for them. So
>
why not just put them in the data object, even though in MVC a data object
>
shouldn't be talking directly with a view?
>
>
What's the way to go?
I've done it in two ways: (1) create a separate datasource class for the
datasource methods, or (2) put them in the window controller. The latter is
easier, because the window controller typically already has access to the
view and the model, both of which are needed to implement the datasource
methods. Also, it feels the most appropriate because, as you say, the
datasource methods are really controller methods.
I haven't found any need to duplicate the datasource routines in the model.
There are only two required datasource routines, and a third if you need
editing access to the outline or table view. They can all be implemented "in
place" in the controller using key-value coding, but I tend to put the data
access parts of them in the model object. The datasource methods for getting
and setting cell values can be thought of as action methods, which you
typically find in a controller. Like most action methods, they can be
written to call corresponding accessor methods in the model object. For a
table view, for example, my ...setObjectValue... method calls a standard
accessor method in the model object, such as ...setCellValue.... Just make
sure the accessor method takes advantage of key-value coding for speed and
efficiency.
--
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.