Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've a simple question about the terminology used in the Delegate pattern;

Let's say I create an object that will be responsible to download something from the Net and when it is finished, will call me back with the result. I guess we can call the downloader object the "delegate", since he is doing work on the behalf of my main object.

If I'm right 'til here, then, I've a problem with the sample codes I read. The property in the Downloader Class is often named "delegate", and put to Self by the creator of this downloader.

Am I wrong or it should effectively be called "delegator" instead ?

share|improve this question
up vote 2 down vote accepted

The delegate is the thing that is performing the sub-task. In your case, Downloader is doing the main task, but then tells the delegate to perform some task. Downloader does not know or care what that task is, just that it has to happen.

If you have to use delegator, it would be Downloader as it is the class that delegates work to something else. But I think that runs into problems because you have multiple words that are similar and lead to confusion like yours. Instead, I tend to think of things in terms of events and listeners. When Downloader finishes, it fires a downloadFinished event and tells any listeners that the event occurred. The listener than decides what it wants to do with that information.

share|improve this answer
Does it mean that I really get the pattern upside down ? To me, the main object is doing the main job, and ask to the "downloader" to do a side job and call him back when it's done. The main object creates a delegate, in that sense. But it seems I 'm wrong, isn't it ? – Pierre Apr 29 '11 at 15:37
@Pierre: It all depends on the scope of what you are thinking. Main is doing a task and creates a Downloader to do a side task. But from the scope of Downloader, it is doing a task and notifying someone else when it finishes. Main doesn't care about what is inside Downloader and Downloader doesn't know Main exists. It is ok if they both have a delegate variable that do different things. – unholysampler Apr 29 '11 at 15:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.