Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
553 views
in Technique[技术] by (71.8m points)

cocoa - 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.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...