Solved

What is a delegate exactly

Posted on 2008-10-29
3
12,296 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 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Which checksum is this? 7 139
C++ check and remove last word from a string 5 141
Inorder binary search tree 5 158
C hashtable library 3 82
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…
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…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

911 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now