I was a bit surprised at first that UIView
's drawing is helped by CALayer
, but CALayer
's delegate is actually UIView
. It seems that the relationship is reversed.
But is it true that, delegate has no "master commander" or "ownership" relationships... it can go any direction: such as, Class A can have a delegate which is Class B, and at the same time, Class B can also have a delegate that is Class A.
Even more, there can be multiple delegates, which means, an object needs help from several other objects.
It is kind of similar to the physical world, that a CTO can delegate the "Technical ability test to interview someone" to David, and now David is a delegate for providing a score of 1 to 10. But David can delegate a requirement met or not back to the CTO (a boolean) that "I can only interview the candidate for Javascript, I will agree the new candidate can be hired and agree to work with him if you find out he is good with scalability issues because our group need such a person" -- and David is delegating this back to the CTO.
So in Objective-C (and probably any language too), there can be multiple delegates, and they can go any direction, and the main idea is just for some "help" that the original object doesn't know how to handle. Is that true?
Delegates in iOS are not really like in real life. The delegates don't actively tell objects how to work, but rather reactively instruct objects as to how they should operate, and receive updates about the status of objects.
The delegate is in place to monitor the status of the objects it is delegating, and to provide instructions (when necessary) on how the object should perform its tasks. Your right in saying that there is no specific ownership, like class A can be a delegate for class B while class B is delegating class A. This is perfectly fine.
There are four main types of delegate methods that both provide the delegate with information about the status of the object, and request instructions from the delegate. PeyloW describes them very well in his answer here.
All of this is a roundabout way of saying that yes, you are correct.