Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Beginning iOS 4 Application Development
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: Beginning iOS 4 Application Development
This is the forum to discuss the Wrox book Beginning iOS 4 Application Development by Wei-Meng Lee; ISBN: 978-0-470-91802-9
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning iOS 4 Application Development section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 27th, 2011, 12:54 AM
Registered User
Join Date: May 2011
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default Delegates - can anyone REALLY explain them?


I've searched up and down the web, Books, Apple's docs and even under rocks in my back yard - and though I've read DOZENS (100's?) of entries, articles, and posts, I haven't found a single REAL explanation to what delegates REALLY are, HOW they work - and WHY we even need them? WHY they're being used, why they exist, what ADVANTAGES they offer programmers - I'm practically astounded by the total lack of any REAL explanations out there on what delegates are.

Its amazing.

I've got a Masters Degree for God's sakes! I've taught in Universities and various Training Centers for years. And I've been coding for years - on and off, some professionally, some semi-professionally - in Actionscript, Javascript, Lingo (anyone remember that?), even Pascal way way back in the 80's when I was a kid!! - I really do understand programming. I may not be a whiz, but I'm no fool either!

So, please, can anyone really explain Delegates - perhaps with real-world analogies. I mean lets not even talk CODE, lets not talk SYNTAX, lets "real-world" it, lets talk CONCEPTS. Give me analogies from the Business World for example, from running the old Lemonade Stand perspective, or running a Baseball team - I dunno - ANYTHING that would make sense.

Reply With Quote
  #2 (permalink)  
Old May 28th, 2011, 10:09 AM
Friend of Wrox
Points: 1,671, Level: 16
Points: 1,671, Level: 16 Points: 1,671, Level: 16 Points: 1,671, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts

I believe I can and will try after the holiday weekend.
For now, delegates are used to extend the functionality of a class without resorting to subclassing. They provide a design pattern that maintains very loose coupling between classes, usually more generic ones like views, and those with application specific functionality. Some of the most common examples of classes that use delegates are windows (in Cocoa), tableViews, and textFields/textViews. A tableView, for example, only knows how to draw itself, and while it could be sub-classed to deal with the presentation and manipulation of the data it displays, that is counter to MVC paradigm. Delegate methods are of the
type. They allow the application to set up constraints, pre and post processing and reactions to events. A simple scenario- Text is entered in a textField and the window containing the textField is about to close. What should be done with the input text? The window and textFields are simply containers, they don't and shouldn't know how to handle it, so their delegate is informed about what is about to occur (-windowShouldClose and -textFieldShouldResignFirstResponder for example) and it is the delegate's responsibility to allow or prevent this from taking place, or take some action before allowing it to occur.
More to come on Tuesday…
If you haven't read Cocoa Design Patterns by Buck and Yacktmann I would strongly recommend it.


Last edited by thepianoguy; May 28th, 2011 at 04:11 PM.. Reason: Missing word
Reply With Quote
  #3 (permalink)  
Old May 29th, 2011, 09:57 AM
Registered User
Join Date: May 2011
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default Explaining Delegates

Bob, I'm assuming that when you wrote in the second line of your response "delegates are used to extend the functionality of a class with resorting to subclassing " - you actually meant to say withOUT resorting to classes?

Otherwise, I'm very much looking forward to your response after the weekend.
You seem to be very active on this forum - I'm fairly new but you've already responded to one of my posts, and I've certainly come across some of your other contributions in my searches here where I've come across your responses to other posts by other users.
In short, its great to see someone be so attentive and forthcoming with their knowledge.

I'm only hoping that you'll indeed find a way to phrase a response on this topic in a manner that isn't 100% code, syntax or theory-talk. As mentioned, a discussion of a real-life process - like managing a baseball team, or running a coffee-shop, or anything we can all relate to from everyday living would definitely be great (not that we all manage baseball teams in our everyday lives :-)) But you know what I mean.

Putting it all together afterwards and bringing it back to code can at that point really drive the whole thing home.
So it'd be great to see something like:

@interface teamManager, or: wildThing <pitchingCoachDelegate> - or something along those lines (those are probably wrong, but the point is to actually turn-into-code whatever concepts / examples are discussed.)
Otherwise, if its yet another example that talks about ''id <UITableViewDataSource>'' etc. - well, there's just so many such posts out there already - they haven't really helped me so far - and I bet there are other folks out there who feel the same way.

Anyway, just an idea.

K - enjoy your weekend!
Reply With Quote
  #4 (permalink)  
Old May 30th, 2011, 03:46 PM
Registered User
Join Date: May 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts

What I wouldn't give, as a beginner, for a source that explained some of these concepts in something closer to plain language.

I've been following the examples in several books, designed for varying stages of the learning process, and I find the syntax is much easier to understand when you have a reasonable grasp of the underlying concepts, but too much jargon often seems just an obstacle.

(I understand that this book in particular is intended for people who already have a certain amount of experience, which probably isn't me, not yet, but I'm hoping to gain something from the challenge.)
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Delegates naresh0407 ASP.NET 4 General Discussion 1 August 23rd, 2010 06:27 AM
C# Delegates Christopher C# 2008 aka C# 3.0 7 November 20th, 2009 05:08 AM
Delegates RalphJr C# 2005 1 April 29th, 2006 08:06 AM
Delegates pramos.21d C# 1 April 11th, 2006 03:43 AM
Help with Delegates mike_remember ASP.NET 1.0 and 1.1 Basics 4 October 4th, 2005 07:32 AM

All times are GMT -4. The time now is 01:24 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.