Re: [Q] am I allowed to call NSTableDataSource informal protocol methods myself?
Re: [Q] am I allowed to call NSTableDataSource informal protocol methods myself?
- Subject: Re: [Q] am I allowed to call NSTableDataSource informal protocol methods myself?
- From: Bill Cheeseman <email@hidden>
- Date: Tue, 27 Apr 2004 18:12:30 -0400
on 2004-04-27 5:09 PM, Jonathan E. Jackel at email@hidden wrote:
>
I think the elegance of using the data source method is quite debateable.
>
Most cocoa programmers would probably tell you to interact with the data
>
model directly, rather than going indirectly through the data source, at
>
least in the ordinary case.
On the other hand, it has been remarked a number of times on this list that
a datasource is an MVP hybrid. It has aspects that are like a model, and
aspects that are like a controller, and in my view the controller aspects
predominate.
In fact, there is nothing to stop you from placing the data itself in a
separate class (or even on an external database) and putting the datasource
protocol methods in their own class. I've done this a number of times. Doing
it this way makes it clearer that, conceptually, the datasource is not the
data but only the means of getting at the data; that is, it is not the model
but a controller. The "datasource," per se, is defined as the class that
implements the datasource protocol methods, which are controller-like
methods to get the data, wherever the data exists.
We all tend to speak loosely of the "datasource" as the repository of the
data (indeed, we usually put the data and the protocol methods in the same
class), but in fact the datasource is only the vehicle through which we get
the data. That is, it is the "source" of the data in another sense of the
word "source" -- more like a broker than a dealer, you might say.
Typically, the datasource protocol's object value method is itself
implemented as a direct call to the array (or whatever) that holds the data.
It can easily contain a single line of code that gets an array element from
an array at the provided index (row number). So it's a little misleading to
describe using the datasource protocol method as "going indirectly." It's
actually going just as "directly" as you would go if you wrote a separate
one-line method that got the same array element out of the same array.
I'm not aware of any reason why you can't just call the datasource protocol
method itself in order to make use of its existing ability to access the
data, instead of wasting time and space reimplementing that same ability in
a separate method. There isn't any magic in the protocol method. It's just
an ordinary Objective-C method that you write yourself. The fact that the
system calls it frequently in the course of displaying the table view
doesn't mean you can't call it yourself, too, when doing so serves your own
purposes.
--
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
_______________________________________________
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.