Example
The following Java example illustrates the "virtual proxy" pattern. The ProxyImage
class is used to access a remote method.
The example creates first an interface against which the pattern creates the classes. This interface contains only one method to display the image, called displayImage
, that has to be coded by all classes implementing it.
The proxy class ProxyImage
is running on another system than the real image class itself and can represent the real image RealImage
over there. The image information is accessed from the disk. Using the proxy pattern, the code of the ProxyImage
avoids multiple loading of the image, accessing it from the other system in a memory-saving manner.
The program's output is:
Loading HiRes_10MB_Photo1 Displaying HiRes_10MB_Photo1 Displaying HiRes_10MB_Photo1 Loading HiRes_10MB_Photo2 Displaying HiRes_10MB_Photo2 Displaying HiRes_10MB_Photo2 Displaying HiRes_10MB_Photo1Read more about this topic: Proxy Pattern
Famous quotes containing the word example:
“Our intellect is not the most subtle, the most powerful, the most appropriate, instrument for revealing the truth. It is life that, little by little, example by example, permits us to see that what is most important to our heart, or to our mind, is learned not by reasoning but through other agencies. Then it is that the intellect, observing their superiority, abdicates its control to them upon reasoned grounds and agrees to become their collaborator and lackey.”
—Marcel Proust (18711922)