You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by Glen Daniels <gd...@allaire.com> on 2001/02/16 15:19:20 UTC

Proxy pattern

Jacek asked me to post my thoughts on this, so here we go.

If you have a SupplierHandler, which does this:

public class SupplierHandler implements Handler {
    Supplier _supplier;
    ...
    public void init() { _supplier.getHandler().init(); }
    public void invoke(MesssageContext msgContext) {
        _supplier.getHandler().invoke(msgContext);
    }
    ...
}

You end up calling potentially different Handler objects on the init() call
and the invoke() call in the case that the Supplier happens to be, say, a
Factory.  If you try to solve the problem thusly:

    Handler _myHandler = null;
    ...
    public void init() {
        if (_myHandler == null)
            _myHandler = _supplier.getHandler();
        _myHandler.init();
    }
    ...etc...

You now have the SupplierHandler in the registry tied to a single Handler
instance, which isn't what you want either (since now you lose the
creational dynamics the Supplier gives you once you call it the first time).

The pattern is still a good one, I think, for some uses - for instance, when
building an instance of a Chain in the registry, you might use
SupplierHandlers to get the right creational patterns for the component
parts inside the Chain.  I just don't think it can be used to replace the
idea of a registry full of Suppliers.

--Glen