For example, I make a MyUIElement, I can accept the user click it. When the user click it, the user can define a method for me when I click it. For example, they can increase the count by 1, when I click it.
So, if I am thinking on how to implement this logic…I can make a MyUIElementDelegate, and call back the MyUIElementDelegate‘ s onMyUIElementIsClicked: function, or I can allow user to addTarget: action: forEvents:. These two ways also works. But what is the different between them? Thanks.
Well, if the method to be called is on the same class, addTarget would be easier but if the method is defined in another class, implementing delegate would be a better idea to invoke the method. With a little bit of extra coding, delegate protocol will give you more flexibility, by the fact that it has two types of methods: @required and @optional.