Class Participation Exercise Proxy Pattern
Class Participation Exercise: Proxy Pattern
Use the Proxy pattern to improve performance by not reading files that aren't actually needed yet.
interface OurFile {
byte[] fileContents(); // returns entire file
String getName();
}
class ConcreteFile implements OurFile {
String name;
byte[] fileContents;
ConcreteFile(String name) { ... }
String getName() { return name; }
byte[] fileContents() { return fileContents; }
...
}
assume ConcreteFile
exists and implements OurFile
. ConcreteFile
reads the entire file when it is constructed.
Write java code for ProxyFile
that proxies a ConcreteFile
and doesn't have to read the entire file until the contents of the file are needed, using the proxy pattern.