Replacers and strategies as first class objects
Why replacers and strategies?
There are many reasons why the product uses first-class replacers and strategies, rather than having the Swapper interact directly with the object to be swapped.
Granularity
Replacers and strategies are fine grained and yet encapsulate an important swapping behavior, the replacements and the selectors that are used. It's easier to understand them individually than the whole ObjectSwapper itself, making it easier to subclass replacers and strategies than to subclass ObjectLoader or ObjectDumper.
Composition
Customizing a given ObjectDumper or ObjectLoader is easier by combining different replacers and strategies than by subclassing. Swapping behavior can be changed back and forth dynamically by plugging different replacers and strategies in an ObjectDumper or ObjectLoader.
Flexibility
Different applications can define different replacement behaviors using customized replacers (say to use a table other than the Smalltalk dictionary when looking for a class by name). Or they may provide a different replacement behavior for an existing class without affecting other instances of ObjectDumper or ObjectLoader and without having to specify a new replacer (for example, CompiledMethod).
Dumping replacers
There are two different kinds of replacers that implement the behavior presented in Dumping replacement. The table below lists the types of replacers and the kind of replacement they provide.
Replacer Type
Replacement Provided
Class Based Replacer
Object replacement based on the class of the original (Class-based replacement)
Instance Variable Replacer
Replacement of individual instance variables of the original object (Instance-variable-based replacement)
An ObjectDumper can be customized with replacers for each of the types above. You should use ObjectDumper instance methods classBasedReplacer: and instVarReplacer:.
For each kind of dumping replacement listed above, an abstract class exists. They are named EswClassBasedReplacer and EswInstVarBasedReplacer. These classes let you subclass replacers and plug instances of the new subclasses in instances of ObjectDumper. The protocol that each type of replacer should implement is listed in the VA Smalltalk Migration Guide.
Loading replacers
Only one kind of loading replacement, class-based replacement, was presented in Loading replacement. One kind of replacer, the loading replacer, implements it. An ObjectLoader can be customized with a loading replacer by using ObjectLoader instance method loadingReplacer:. This message plugs a new replacer in the ObjectLoader. There is an abstract class for a loading replacer, EswLoadingReplacer. This class lets you subclass a loading replacer and plug an instance of the new subclass in instances of ObjectLoader.
Last modified date: 05/19/2020