Shadows


Neil Rotstan

Version/Date: $Id: shadows.aft,v 1.2 2001/12/31 02:09:03 willhelm Exp $


Shadows are special kinds of objects, derived from the shadow.Shadow class, that implement dynamic runtime extension. When a target object is "shadowed," all of the methods in the shadow object become a part of the target object. If there exist any methods in the shadow object that also exist in the target object, then the methods in the shadow object override those in the target object. When the shadow is removed, the target object goes back to normal.

Shadows are useful for temporarily altering the behavior of an object. For example, suppose a spell is supposed to double the healing rate of a person. The spell effect could be implemented as a shadow that overrides a player's heal method, doubles the argument value (if it's positive), and then passes the new argument to the player's original heal method. When the spell effect wears off, the shadow is removed, and the player's healing goes back to normal.

Shadows can also be used to add additional functionality to a small subset of a group of objects. For example, a guild may place a shadow upon all of its members that add some additional methods to the players that can be used by various aspects of the guild code.

Multiple shadows can be placed upon an object, in which case those shadows are layered. That is, just as a first shadow overrides methods in a target object, a second shadow will override methods both in the target object and in the first shadow. A third shadow would override methods in the target object, first shadow, and second shadow. And so on. Note that, although shadows can be added to an object in any order, they must be removed in the opposite order in which they were added (that is, the most recent shadow must be removed first, and the original shadow must be removed last). The popShadow method in the mudlib.core.Object class automatically takes care of this.

See the documentation for the shadow module for more details.



This document was generated using AFT v5.077