I am confused about the @protocol—-@end in iphone, what actually is it meant for. Why we are using this. Is it a functionality to provide additional methods to a class..? i am not sure.
Please help me.
Thanks,
Shibin
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.
protocol is used to declare a functionality which is going to used by many objects or classes.
Consider an example, You are developing a birds database. So you will be having the bird as a Base class and you will inherit the bird to create your own bird. so in bird class you will not be having any definitions but some behaviors which all birds will have to inherit. Like birds can fly, has wings like that. So what will you d is you will declare all those behaviors and implement them in your derived classes. Because there may be birds which cal fly high and for long distance and some will fly short distances.
For serving this purpose @protocol is used. Using @protocol you declare some behaviors. And use those behaviors in your other classes for implementing the behavior.
This will avoid the overhead of declaring same method again and again and makes sure that you implement the behavior in your class.