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
Thomas a Kempis

... them at their conversion. General Gordon carried it with him to the battlefield. Few books have had so extensive a circulation. The number of cou ...

 
 
 
This page was created in 30.7 ms