Encyclopedia > Delegation

  Article Content

Delegation

Delegation is handing a task over to a subordinate.

In object-oriented programming it is a very simple yet very powerful concept: handing a task over to another part of the program. In OO it is used to describe the situation wherein an object passes a task to another object.

In C++ say there is a class A defined as...

 class A 
 {
   public:
     foo()
     {
       cout<<"Object A doing the job";
     }
 };

Now if there is another class B defined as...

 class B
 {
   public:
     A a;
     foo()
     {
        a.foo();
     }
 };

... any object of class B will delegate the execution of its function foo to an object of class A.

It is possible to extend this idea by making A a virtual base class and foo a pure virtual function. In that case one can further extend object A via sub classes. The result would be that during run time depending upon the subclass of the actual object stored in the variable "a" declared in class B, an appropriate foo would be called.



All Wikipedia text is available under the terms of the GNU Free Documentation License

 
  Search Encyclopedia

Search over one million articles, find something about almost anything!
 
 
  
  Featured Article
Holtsville, New York

... and 4,454 families residing in the town. The population density is 943.4/km² (2,444.3/mi²). There are 5,418 housing units at an average density of ...

 
 
 
This page was created in 21.5 ms