[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

dynamic inheritance -- icons

I was giving a small talk (heh) on Self and I came up with a neat
dynamic inheritance tool.

The example I gave was modelling a factory where things broke.  Say
you have 15 possible ways that things can break, and things could
break in all 15 ways at once.  Each type of break represents new
behavior, so in Smalltalk you'd have to make 15! classes to represent
all the combinations of behavior, if you were using classes to model
the behavior.  An alternative would be to use variables to represent
the aquired breaks and make some kind of delegation scheme or
something.  Since breakage can affect arbitrary other behaviors of an
object, it makes sense to use inheritance to model it.

The construct I came up with to handle this is called an icons.  Here
is its definition (I haven't tested this, btw):

prototypes _AddSlotsIfAbsent: (| icons = (). weakIcons = () |).

prototypes icons _Define: (|
	iCAR* <- lobby. "or whatever -- an 'empty' object"
	iCDR* <- lobby. "or whatever -- an 'empty' object"

prototypes weakIcons _Define: (|
	iCAR** <- lobby. "or whatever -- an 'empty' object"
	iCDR* <- lobby. "or whatever -- an 'empty' object"

Now just represent your objects in the factory with weakIcons objects
having the iCAR set to the object.  The inheritance level of iCAR lets
the iCDR override the behaviors in the iCAR.  To add behavior to the
factory object, just add icons (not weakIcons) objects to the 'chain'
and they will override the normal behavior of the object.

	-- Bill