Delegate Object

The delegateObj.t module creates a dynamic delegation object that an object can delegate work to. This object's state is set to that of the delegating object, so that the delegated object knows what the calling object knows.

 

This mechanism is useful in cases where TADS 3 language 'delegated' keyword is not appropriate. For example, suppose we have the following objects defined:

 

xObj: object

{

attr1  = 'a'

attr2  = 'b'

attr3  = 'c'

 

method1a() { delegated yObj.method1(); }

method1b() { delegateTo(yObj,&method1); }

method2() { "hello xObj 2 <<attr1>>"; }

method3() { "hello xObj 3 <<attr3>>"; }

}

 

yObj: object

{

attr1  = 'd'

attr2  = 'e'

attr4  = 'f'

 

method1() { return method2(); }

method2() { "goodbye yObj 2 <<attr1>>"; }

method4() { "goodbye yObj 3 <<attr3>>"; }

}

 

Suppose we want xObj to delegate its method1a() call to yObj. Using the TADS 3 'delegated' keyword the call chain would look like this:

 

xObj.method1a() calls yObj.method1()

yObj.method1()  calls xObj.method2()

 

and this displays:

 

'TADS 3 DELEGATED : hello xObj 2 a'

 

Suppose we use the delegateTo() method of createDelegate.t. The  call chanin from xObj.method1b() would look like this:

 

xObj.method1b() calls yObj.method1()

yObj.method1()  calls yObj.method2()

 

and this displays:

 

'DELEGATE TO METH : goodbye yObj 2 a'

 

In this case the method calls for delegatedTo() all remain within the  yObj delegation, which has been set to the same state as the calling  object. In addition the yObj delegation synchronizes the state of the calling object, if desired.

 

 

 

 

 

 

 

 

This file is part of the TADS 3 Proteus Library Extension

Copyright © 2001-2004 Kevin Forchione. All rights reserved.