Solved

What is a delegate exactly

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sameEnds challenge 3 180
Super Scope, DHCP 5 91
SQL Server 2008 R2, need a pivot/cross tab query... 4 29
Windows Server 2012 R2 - connect to computer 13 38
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…
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…
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.

830 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