Another Approach to the Protection Proxy: Adding Helper Classes

Protection Proxy with DataLoaded Helper Classes
In the original article, I questioned the practice of hauling a reference to the output UI all the way through the program. However, focusing on the design pattern, I didn’t concern myself with certain details that would have been optimal in a larger sense. Also, I don’t like using helper classes when trying to focus on the basics of a pattern. So, I just put in bare essentials hoping that readers will better be able to see how the pattern works.
However, I’m always looking for better ways of programming, and to misquote Ralph Waldo Emerson,
Build a better proxy and the world will beat a path to your door.
So download Gil’s code, and let’s take a look at it:

A Better Mousetrap
The revision of the Proxy was by Gil Amran and here, in Gil’s words, is what was changed:
I’ve changed few things:
- I used AbsSubject and not the interface. (Abstract class)
- I’ve overrided the clone method in the 2 custom events.
- I’ve re-dispatched any events that came from he realSubject
Further Gil notes,
The AbsSubject extends EventDispatcher, and there’s no way to avoid that. Because the actual loading takes time and works with events, using callbacks might be another way to solve this and not use events.
In comparing Gil’s proxy with the original, the key differences are in handling events. Figure 1 is a file class diagram of Gil’s protection proxy you can compare to the original:

Figure 1:Protection Proxy with Event Dispatch Classes
The two helpers classes function to deal with event handling and dispatch.
Read more…









Bill Sanders
Recent Comments