Method Wrappers


Method wrappers can add hidden behavior to a method without recompiling it. They can be used to change a method's behavior. Commonly, they are used to add behavior before and after the default method executes. For example, we can create a coverage tool by using a method wrapper that increments a counter when it is called.


WARNING: Incorrectly using the wrappers can crash your image, so you should save your image before using them. Most problems occur as a result of installing them on methods that are called either in the beforeMethod or afterMethod which results in infinite recursion.


User instructions:

To install the method wrappers, simply parcel-in the MethodWrapper.pcl file from MethodWrappers.zip into a VisualWorks® 3.0 image. The other files (Coverage.pcl, Synchronization.pcl, and Interaction.pcl) can be parceled-in in any order or not at all. A description of these files can be found on this page.

To use a method wrapper, send the class an on:inClass: message to the class of the method wrapper you want to create. The first argument is the selector for the method, and the second is the class that defines the method. This returns a new method wrapper which can then be installed the by sending the install message and uninstalled by sending uninstall message.

To create a new type of method wrapper, you must create a subclass of MethodWrapper and redefine the beforeMethod and/or afterMethod to add your specific behavior for the wrapper. If you only need to redefine the beforeMethod, you can redefine the valueFrom:arguments: method instead (see the CountMethodWrapper). This is somewhat faster since it doesn't need to create two blocks and send the valueNowOrOnUnwindDo: message.


Bugs/Limitations:


Comments or suggestions can be sent to brant@cs.uiuc.edu.
Last updated on 20-Apr-99.