Proxy pattern. Confusion in Virtual Proxy ?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   mahesh_beri
Posted On:   Tuesday, September 11, 2001 09:41 PM

In many books on patterns including the GoF,the example given is "a proxy can defer the creation of expensive object until it is required" Example given is that of ImageProxy for the Image object which loads the image from disk. The book says that in response to request from the editor the ImageProxy can return the size information from the cache without loading the image. How is it possible ? In same chapter furthur the authors have given an implementation where the getExtent() method in the ImageProxy really loads the image in case it is not loaded. Then where do we gain in this whole process, because we are not deferring the object creation . Please suggest !    More>>

In many books on patterns including the GoF,the example given is "a proxy can defer the creation of expensive object until it is required"


Example given is that of ImageProxy for the Image object which loads the image from disk. The book says that in response to request from the editor the ImageProxy can return the size information from the cache without loading the image. How is it possible ?


In same chapter furthur the authors have given an implementation where the getExtent() method in the ImageProxy really loads the image in case it is not loaded. Then where do we gain in this whole process, because we are not deferring the object creation .

Please suggest !

   <<Less

Re: Proxy pattern. Confusion in Virtual Proxy ?

Posted By:   Bozidar_Dangubic  
Posted On:   Wednesday, September 26, 2001 06:18 AM

perhaps you have a document. this document contains system architecture which consist of text and images showing various UML diagrams. lets also say that you are creating your own viewer for this document in swing. what you can do is load all the text at first and place proxies for all images in the document. the document loads extremely fast because it is loading only text. for each UML diagram, there is a link stating something like "click here to see UML diagram" if the user clicks the link, the image is loaded into the document. what you gain is 1) documents loads fast so user can immediately start browsing it. 2) if the user is not interested in the UML diagrams, it does not have to wait for them to load. 3) if some UML diagram is really, really big, the user can read the document while the image is getting loaded. this technique is also commonly used in HTML documents containing diagrams which are shown as tiny pictures that expand in another window when clicked.
About | Sitemap | Contact