특정 객체에 대한 접근을 제어하거나 기능을 추가할 수 있는 패턴이다.
public interface GameService {
void startGame();
}
public class GameServiceProxy implements GameService {
private GameService gameService;
@Override
public void startGame() {
long before = System.currentTimeMillis();
if(this.nameService == null) {
this.gameSerivce = new DefaultGameService();
}
gameService.startGame();
System.out.println(System.currentTimeMiliis() - before);
}
}
public class DefaultGameService implements GameService {
@Override
public void startGame() {
System.out.println("이 자리에 오신 여러분을 진심으로 환영합니다.");
}
}
public class Client {
public static void main(String[] args) {
GameService gameService = newGameServiceProxy();
gameService.startGame();
}
}