CS193p Delegation concepts

Delegation is a rather difficult concept to understand. In order to get a better idea what it is I made a drawing.

Delegation

Suppose we have three object: a square, a circle and a pentagram. The square has four white holes in itself (an oval, a 4-pointer star (not quite white), a 5-pointed star and a hexagram). It announces to the world that another object can fill these holes (the lines protruding the square). In fact it needs two other objects: one for the blue holes and one for the red holes.

The circle object announces that it will help the square object with its blue holes. And the pentagram object says it will help with the red holes. Thus the circle object fills the blue oval hole of the square object. And the pentagram object fills the red pentagram hole and the 5-pointed star hole of the square object. The four pointed star has not been filled as it was optional (not quite white).

With this it is possible to explain the various delegation concepts:

These leads to the five steps defined in course 7(?). Two steps are definition and three steps are adoption:

  1. Protocol - define the methods for a protocol;
  2. Delegator - define who needs to delegator a protocol;
  3. Adoption - a class (delegatee) should declare it adopts a certain protocol;
  4. Implementation - the delegatee should implement the methods required in the protocol by the delegator;
  5. delegator properties - the delegator properties that point to its delegatees should be set;

Categories: Computingcs193p
PermaLink Comments

Page 1 of 1 pages