Alex Rivera | Logout

What's the difference between data source and delegate?

Asked 2010-02-09T20:01:18.857
44

I have a fundamental question related to Cocoa frameworks design patterns.

What's the difference between delegate and data source?

Both of them could use @protocols declaration, but some classes or frameworks are using delegate, and some others are using datasource.

All I can understand from UI/NSTableView is the delegate respond to UI-related events, while the datasource is purely related to the data. But, I don't know any data source implementations outside the UI classes of Cocoa.

Note:

  • The delegate I mentioned in this question is not always related to UI events.
  • The data source question has been answered.
Edit
Report

1 Answer

8

From my point of view, a DataSource is an object that doesn't know where the data is, and thus you should provide it. Such as telling an object how many items in a column.

A Delegate, which is a part that object shows to you, must be implemented by your class, because the object knows where the data is, but it does not know how to use it correctly.

answered 2012-05-22T00:00:10.613

Your Answer