Can anyone out there explain them using analogies to some real-life processes – like running a Baseball team, or a coffee shop, or an Auto-Mechanic’s Shop – anything that would MAKE SENSE?
Like lets not even talk CODE, or SYNTAX, or programming – I’ve seen plenty of those posts and none of them really do it for me – can we just talk concepts first?
Like I don’t even understand WHY we have them, how they’re advantageous, etc.
Show me the real-world analogy of a process run with and without delegates, so I can see what makes them so useful and great.
Then we can code-it-out.
(And FYI, my specific interest is in Objective-C/iPhone App Development implementation – but I really think understanding this conceptually first is much more important.)
thanks in advance!
specialists
Customer: Hi – did you fix my car?
Employee: I estimate that we’ll have a chance to look at it in less an hour. I’ll call you when it’s ready.
Customer: I’ve already waited 30 minutes, and I’m really in a rush!
Employee: We’re very busy at this time of year.
Customer: You don’t seem busy; you’ve been at the front desk the entire time!
Employee: I’m not a mechanic. I am the manager. Do you still want me to fix your brakes?
The manager’s good at what he does; he details problems for the customers, orders blinker fluid, makes the schedule, and does payroll. Although he likes cars and knows a lot about them, he’s not a specialist at repairing them. The manager’s capable of doing many things at the shop, but it’s the mechanics that have the expertise required to fix the customer’s brakes.
One of the most common reasons delegation is used is to avoid subclassing (that would be like sending the manager to school to become a mechanic – an analogy which looks a lot like multiple inheritance). When subclassing could be used to specialize, delegation may often be used instead. Delegation is a looser bond where (in a good design) one object fulfills all or most of the duties, but leaves frequently specialized portions of its duties to other implementations (the delegates).