Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between data source and delegate?

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.
like image 237
Jesse Armand Avatar asked Feb 09 '10 20:02

Jesse Armand


People also ask

What is tableView delegate and datasource?

Datasource methods are used to generate tableView cells,header and footer before they are displaying.. Delegate methods provide information about these cells, header and footer along with other user action handlers like cell selection and edit..

What is data source in iOS Swift?

To manage the data, you provide the table with a data source object — an object that implements the UITableViewDataSource protocol. A data source object responds to data-related requests from the table. It also manages the table's data directly, or coordinates with other parts of your app to manage that data.

What is the difference between delegate and protocol in Swift?

Protocol is a set of methods (either optional or required) that would be implemented by the class which conforms to that protocol. While, delegate is the reference to that class which conforms to that protocol and will adhere to implement methods defined in protocol.

What does delegate mean in programming?

A delegate is a type that represents references to methods with a particular parameter list and return type. When you instantiate a delegate, you can associate its instance with any method with a compatible signature and return type. You can invoke (or call) the method through the delegate instance.


1 Answers

The datasource supplies the data, the delegate supplies the behavior.

In MVC, datasource is in the model layer and the delegate is in the control layer.

Actually, on second thought, the datasource is usually controller that is lower down, closer to the model. I don't think I've ever used a model object as my datasource.

like image 76
kubi Avatar answered Sep 30 '22 18:09

kubi