Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

What is a delegate exactly

Posted on 2008-10-29
3
Medium Priority
?
12,364 Views
Last Modified: 2013-11-25
I have been 'programming' in Access and VBA for years and outside of High School and College programming classes years ago, that is the extent of my programming.  I am now trying to learn Objective-C to create Iphone apps.  I got a couple great books and found some great tutorial sites, but I have some 'basic' questions that I can not seem to find the answers to anywhere (yeah, this is the same 'into' I used in another question, sorry)

Even in the basic 'Hello World' examples they use SuchAndSuchAppDelegate.  If I remember correctly, one web tutorial says something like 'we are not using the AppDelegate in this project...' What the heck is a delegate and how do you know when to use it or not?

Thanks in advance,

Michael
0
Comment
Question by:UniqueData
3 Comments
 
LVL 3

Accepted Solution

by:
Blackninja2007 earned 1000 total points
ID: 22840220
In essence, a delegate is a type-safe object that points to another method (or possibly
multiple methods) in the application, which can be invoked at a later time. Specifically speaking,
a delegate type maintains three important pieces of information:

" The name of the method on which it makes calls
" The arguments (if any) of this method
" The return value (if any) of this method

Once a delegate has been created and provided the aforementioned information, it may dynamically
invoke the method(s) it points to at runtime.

0
 
LVL 5

Assisted Solution

by:AJVienna
AJVienna earned 1000 total points
ID: 22844200
A real world example of a delegate would be:
You have a Person A.
Now you ask Person A to do Task A.
If person A has a delegate for this it would ask its delegate (e.g. Person B) to perform Task A for it.

Delegates are quite useful. Since it often allows to customize the functionality of the class without the need to derive from it. The is especially useful if you only need to customize a very small set of methods. Cocoa uses lots of delegation.

You can also find more information of this in a book regarding Design Patterns or in wikipedia:
http://en.wikipedia.org/wiki/Delegation_pattern
0
 
LVL 7

Author Comment

by:UniqueData
ID: 22898304
Thank you much for your posts.  I will chew on this info and read the link.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question