From the course: Java Design Patterns: Structural

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Implement the Proxy pattern

Implement the Proxy pattern - Java Tutorial

From the course: Java Design Patterns: Structural

Start my 1-month free trial

Implement the Proxy pattern

- [Instructor] Now we can make some changes, to this image gallery up, so that it consumes less memory, by implementing the proxy pattern. To do this, I'm going to create a proxy image object, which will only call the expensive load method when it's needed, and will only ever call at once. So first, I'm going to create a new Java class, by right clicking on the source package and going to new Java class. And I'll call this image proxy. I'm going to make sure this implements the display object interface, so that it can be used interchangeably with the image file class. I'm going to create two new fields for this class. One of them is going to be of type string, called path. And the other is going to be of type imageFile, which I'll call image file. I need to have a constructor for this class too, because like the image file class, I need to pass in the path to the image I want to display. So I'll do public Image…

Contents