[DGD] Dynamic inheritance

Shevek shevek at btinternet.com
Mon Dec 24 18:20:31 CET 2001


Had another thought on this subject, although if the big object stats are 
good it's likely to be unnecessary.

The idea works something like this.

Instead of inheriting code you use only a single master copy of the 
functions that 'inheritable' object has. When your clone object wishes to 
inherit those functions it makes a call to, for example, register() which 
returns a mapping containing a list of functions, and a list of variable 
names and types. Within the clone object you maintain a mapping of object 
arrays, string arrays, int arrays, objects, strings, ints etc. Then once 
the clone calls register() it stores all the information that the 
'inherited' object needs. Then have some processing to a) If present call 
the function in the clone or b) Search the list of functions to find which 
master object to call the function in.
It also means a lot more call_other() commands, which may not be a 
particularily good thing. However it does make it possible to change the 
'inherited' functions and data for a particular clone on the fly.

Once again I read through and see I haven't really explained that very well :>
I'll try to clarify.

Clone object:
contains:
an array inherited->list of inherited objects by filename
a mapping functions->[name of inherited object][function]
a mapping variables->[name of inherited object][variables] ->Seems this 
should be mixed.
a function add_inherit->calls register in the inherited object and sets 
everything up.
a function remove_inherit->reverse of add_inherit.
a function process->checks if function is present in clone or performs the 
correct call_other.

Inherited object:
function register->Returns a list of all functions and variables used in 
the inherited object.
Object contains only functions, not global variables.

No global variables because the inherited code can be used by multiple 
clones so any globals would  cannot be guaranteed to relate to the calling 
clone.
The call_other in the clone passes the required variables in by reference, 
ie as pointers, so that the inherited code works on the actual values not 
copies of them. So when calling a function in the inherited object you pass 
over a reference to all the variables it registered in the clone object 
(using that variables mapping).

I don't know how clearly I've managed to explain that, hopefully enough 
that you can fill in the blanks. As I said at the top if the stats on 
having one big object are good then this is probably just unnecessary 
complexity.

Cheers,
	Shevek 

_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list