Design Patterns - Proxy Pattern
Key words: Remote, Virtual, Protection Proxy, Security, Caching
Remote - Resource from different server, namespace, project
Virtual - Cache, Control access to expansive methods
Protection - Security
UML
Proxy Pattern
Pseudo Code
class BookParser implements IBookParser {
public BookParser(String book) {
// Expensive Parsing
}
public int getNumPages() {
// Some Logics
}
}
interface IBookParser {
int getNumPages()
}
class LazyBookParserProxy {
private Book book = null;
private BookParser parser = null;
public LazyBookParserProxy(String book) {
this.book = book;
}
public int getNumPages() {
if(parser == null) {
this.parser = new BookParser(this.book);
}
return parser.getNumPages();
}
}