design patterns : proxy
This commit is contained in:
9
design-pattern/gof/src/proxy/after/Client.java
Normal file
9
design-pattern/gof/src/proxy/after/Client.java
Normal 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();
|
||||
}
|
||||
}
|
||||
11
design-pattern/gof/src/proxy/after/DefaultGameService.java
Normal file
11
design-pattern/gof/src/proxy/after/DefaultGameService.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
6
design-pattern/gof/src/proxy/after/GameService.java
Normal file
6
design-pattern/gof/src/proxy/after/GameService.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package proxy.after;
|
||||
|
||||
public interface GameService {
|
||||
|
||||
void startGame() throws InterruptedException;
|
||||
}
|
||||
18
design-pattern/gof/src/proxy/after/GameServiceProxy.java
Normal file
18
design-pattern/gof/src/proxy/after/GameServiceProxy.java
Normal 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);
|
||||
}
|
||||
}
|
||||
9
design-pattern/gof/src/proxy/before/Client.java
Normal file
9
design-pattern/gof/src/proxy/before/Client.java
Normal 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();
|
||||
}
|
||||
}
|
||||
9
design-pattern/gof/src/proxy/before/GameService.java
Normal file
9
design-pattern/gof/src/proxy/before/GameService.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package proxy.before;
|
||||
|
||||
public class GameService {
|
||||
|
||||
public void startGame() {
|
||||
System.out.println("이 자리에 오신 여러분을 진심으로 환영합니다.");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user