--Originally published at diegotc2016
Delegation is when a class “delegates” another class to do something.
Delegate is to give the power you have to do something to another person in order to do something.
In OOP delegation is when a class gives one or more functionalities to another class in order to do something.
Here’s an example:
Some parents want to go out. They hire a babysitter and tell her to look after the baby.
But what if the baby gets sick?
There’s a note on the fridge door. “In case of emergency phone Helen 555-3141”
This is a pretty good analogy for delegation. Helen is the
delegate.
//within the parent class
babysitter.delegate = helen
[babysitter lookAfter:baby]//within the babysitter class
if (baby.isSick)
{
[delegate callAbout:baby]
}
When assigning actions to an object, you can provide that object with a delegate. The delegate will be called when the object needs to inform something or do something beyond the scope of the object.
Where I got this information from?
http://es.thefreedictionary.com/delegar
https://www.quora.com/What-is-delegation-in-object-oriented-programming
https://es.wikipedia.org/wiki/Delegaci%C3%B3n_(inform%C3%A1tica)

