I usually read a word ‘delegate’ in the apple document and their library book. What exactly meaning about this word? Any special meaning in iPhone?
Thank you very much.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Delegates are a design pattern in object-oriented languages that allow an object to “call out” to unknown code to perform activities or calculations that that object cannot effectively do on its own. Let’s say you have a class Dog:
The delegate object is generally supplied by the code that instantiates
Dog, and is called upon by that instance to do things that the dog itself can’t do. For instance, consider this interface of theDogDelegateprotocol, which defines what theDog‘s delegate object is expected to do:In this case, an instance of
DogDelegateis often the owner of theDog(and, in Objective-C, a delegate often owns an object, so this lines up nicely with the metaphor.) The dog, when it needs to go out for… dog activities… will ask its delegate to perform the-letDogOut:method, placing the dog in the backyard. When done, it will ask its delegate to perform the-letDogIn:method, bringing the dog back inside. When the dog wants affection, if its delegate is able to, it will ask the delegate to scratch it for some period of time using-scratchDog:forTimeInterval:.