The Swapper framework
This section describes the major components of the Swapper framework for users who wish to perform more advanced tasks such as the following:
Define different replacement methods in the same class (see Summary on replacement).
Use highly customized replacement, according to the application's needs.
In general, the swapping framework assumes three major components in a swapping operation:
1. The object to be swapped (loaded or unloaded)
2. The object that will perform the object swapping (either ObjectLoader or ObjectDumper)
3. A Replacer, which may define replacements for specific objects or instance variables of objects
4. A Strategy, which routes messages from the replacers to the target objects, thus providing a centralized point so selector names can be overridden by different applications
An ObjectSwapper (ObjectDumper or ObjectLoader) does not send messages directly to the object to be swapped (loaded or unloaded). Instead, it uses an ObjectReplacer as an intermediary. The public API is between ObjectReplacers and ObjectSwappers (an ObjectReplacer may need to send messages back to the ObjectReplacer). An ObjectReplacer interacts with the object to be swapped through the Strategy, using a public API. Messages between the strategy and target objects can be defined by new applications.
On the other hand, the object to be swapped may need to send messages back to the ObjectReplacer (or even back to the ObjectSwapper). However, note that the ObjectSwapper itself does not send messages to the target object (to be loaded/unloaded) to compute replacements.
The Swapper framework comes with a predefined set of ObjectReplacers. For most of the cases (such as new classes added by the user, which need a special replacement when loaded or unloaded), just redefining messages that strategies use to interact with the target object (to be loaded/unloaded) is sufficient. This is described in Object replacement. Advanced users may want to define their own ObjectReplacers or Strategies. For that, they must respect the API between an ObjectSwapper and an ObjectReplacer, and between these and Strategies. The messages between Strategies and target objects are defined by the application.
The sections that follow explain why ObjectReplacers are first-class objects, and why this is important. It also presents the different forms of replacers and how to define them for different kinds of use (flexibility, speed, etc.).
Last modified date: 10/16/2017