Solved

What is a delegate exactly

Posted on 2008-10-29
3
12,344 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Accepted Solution

by:
Blackninja2007 earned 250 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 250 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

Technology Partners: 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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
Suggested Courses

624 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