Navigation:  Programming Cookbook > Binary Filing Objects > Customising storage >

Creating an STB Proxy class

Previous pageReturn to chapter overviewNext page

You need to create a new subclass of STBProxy with instance variables to hold the crucial data. The proxy cannot, of course, contain the object that it trying to represent as this would cause and endless recursion. There are two main types of proxy, those that

1.generate a new object,
2.represent a way of finding an existing object.

If the proxy generates a new object then its #fixup:at: should instantiate a new object instanciated from its stored data and use #become: to swap it for the proxy thus resolving any other references to the proxy. In most cases you can just implement a #value method which answers the new instance and inherit the #become: behaviour from STBProxy.

If the proxy represents a way of finding an existing object then using #become: is going to have disastrous consequences for those objects that refer to the existing object. In this case your proxy will need to re-implement #fixup:at: method, sending STBInFiler>>#fixup:to: to fixup the filer to the desired object. Finally, answer the new object. e.g.

fixup: anSTBInfiler at: proxyIndex

  "Private - Tell anSTBInFiler to replace in its

  map of read objects the entry at proxyIndex

  (the receiver) by the object we specify.

  We must answer the new object."

  | newObject |

  newObject := Magic find: key.

   anSTBInFiler fixup: proxyIndex to: newObject

  ^newObject

 

STBInFiler>>#fixup:to: only replaces the proxy itself by the new object - it can not fixup up any other references to the proxy, so such a proxy should not contain any references to itself. However, if self references by the proxy are unavoidable then you can use #oneWayBecome: to fixup the nested references but note that this method is slower than #become:.