Server Smalltalk Guide : Appendix A. Extensions to Kernel : SstRegistry and SstDualRegistry
SstRegistry and SstDualRegistry
Registries are a form of <keyedCollection>. Registries maintain dual mappings between a key and object, also known as a bijection: a key maps to one object, and each object is mapped to by only one key. Thus an object can be looked up to find its unique key. Registries also allow arbitrary objects to be "added", allocating new keys as necessary and preserving existing mappings for objects already added. SstDualRegistry are more efficient for situations requiring frequent key lookup given its object.
Registries are created giving a keyClass and objectClass, which should adhere to <keyedCollection>. The objectClass is used to map keys to their objects while the keyClass is used to map objects to their keys. The choice of these classes is very important to preserve the bijections maintained by the registry; the wrong choice of class will dramatically affect the behavior of the registry. These classes are usually either a LookupTable/Dictionary or an IdentityDictionary.
A rule of thumb for choosing the appropriate class is as follows: if the destination object (the object used as the value of the class) supports equivalence, then the class must be an IdentityDictionary. For example, if the keys of a registry are Symbols (which do not support equivalence) and the objects are Strings, then the keyClass must be an IdentityDictionary and the objectClass can be a LookupTable. Consider if the registry was asked to map 'foo' to foo and 'foo' copy to bar. Since String supports equivalence, then 'foo' and 'foo' copy will be equivalent. And if the keyClass (used to map the objects to their respective key) isn't identity-based, then 'foo' and 'foo' copy will map to same symbol and thus not preserving bijections. Thus, the keyClass must be an IdentityDictionary. But since Symbol does not support equivalence, the objectClass (mapping keys to their object) can be a LookupTable. If this confuses you, then a safe heuristic is: if both the keys and objects support equivalence, then use LookupTable. Otherwise use IdentityDictionary.
Registries mostly adhere to protocol and provide some additional protocol for determining reverse mappings.
Last modified date: 01/29/2015