design patterns : proxy

This commit is contained in:
haerong22
2021-12-11 17:58:22 +09:00
parent faba67f357
commit 67f3a09433
6 changed files with 62 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
package proxy.after;
public class Client {
public static void main(String[] args) throws InterruptedException {
GameService gameService = new GameServiceProxy();
gameService.startGame();
}
}

View File

@@ -0,0 +1,11 @@
package proxy.after;
public class DefaultGameService implements GameService{
@Override
public void startGame() throws InterruptedException {
System.out.println("이 자리에 오신 여러분을 진심으로 환영합니다.");
Thread.sleep(1000L);
}
}

View File

@@ -0,0 +1,6 @@
package proxy.after;
public interface GameService {
void startGame() throws InterruptedException;
}

View File

@@ -0,0 +1,18 @@
package proxy.after;
public class GameServiceProxy implements GameService {
private GameService gameService;
@Override
public void startGame() throws InterruptedException {
long before = System.currentTimeMillis();
if (this.gameService == null) {
this.gameService = new DefaultGameService();
}
gameService.startGame();
long after = System.currentTimeMillis();
System.out.println(after - before);
}
}

View File

@@ -0,0 +1,9 @@
package proxy.before;
public class Client {
public static void main(String[] args) throws InterruptedException {
GameService gameService = new GameService();
gameService.startGame();
}
}

View File

@@ -0,0 +1,9 @@
package proxy.before;
public class GameService {
public void startGame() {
System.out.println("이 자리에 오신 여러분을 진심으로 환영합니다.");
}
}