Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to call a reference property "delegate"?

In my app I have a storyboard with two scenes. The first one is a Summary-View-Controller and just shows some data. But you can tap on it and switch to a Edit-View-Controller scene where you can make changes. To report the changes back to the Summary-View-Controller the Edit-View-Controller will get a reference to his parent. When editing is done he will call a method in his Parent-View-Controller.

The property in the Edit-View-Controller looks like that:

@property (weak, nonatomic) id <NameEditViewChangedProtocol> parentController;

My app works fine. That is not my problem. But in many tutorials I read a property like this is just called delegate.

@property (weak, nonatomic) id <NameEditViewChangedProtocol> delegate;

I know what delegation is and how it works but for me parentController is a more meaningful name. delegate, that could just be anything. So my question is: When should I call a property like this delegate? Are there any rule how to use this name?

like image 215
TalkingCode Avatar asked Feb 20 '26 21:02

TalkingCode


1 Answers

I know what delegation is and how it works but for me parentController is a more meaningful name. delegate, that could just be anything.

I think you've answered your own question here. A delegate is a helper object that "could just be anything" as far as the delegating class is concerned. The name parentController assumes something specific about the relationship between the two objects. If you know that that relationship will always exist, then it's appropriate to use that name. On the other hand, if the two objects only happen to have that relationship, but the relationship isn't important to the fact that one object is using the other as a helper, then use delegate (or something similar).

So, is it necessary that the objects in question have a parent/child relationship? Are you sending messages to parentViewController specifically because it's the parent? Or is it conceivable that some other object could respond to the same messages?

like image 183
Caleb Avatar answered Feb 22 '26 11:02

Caleb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!