From the course: Java Design Patterns: Structural
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Recognize where to use the Proxy pattern - Java Tutorial
From the course: Java Design Patterns: Structural
Recognize where to use the Proxy pattern
- [Instructor] In this example, I've got an app that shows images in the style of a slideshow. The app contains a folder called resources, which contains 10 different pictures, image1, image2, image3 and so on. At the moment, my app risen image file from disk every time a new image is created, but if I implemented the proxy pattern, I wouldn't have to do this. This app has an interface called DisplayObject, and this defines a single method called display. At the moment, I've just got one concrete implementation of DisplayObject, which is the ImageFile class. This class has a field called image, which is of type BufferedImage. In the constructor a String is passed in, and this String is the absolute path of the ImageFile that's going to be loaded in to create the actual image. Inside the constructor, I'm assigning the ImageField by calling a method called load and passing in the file path to the image. Inside the load…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.