νλ‘μ
νλ‘μ ν¨ν΄μ λ§κ·Έλλ‘ κ°μ²΄λ₯Ό λμ ν΄μ λ리μλ₯Ό ν΄μ€λ€λ μλ―Έμ΄λ€.
νλ‘μ ν¨ν΄μ μ¬μ©νκ² λλ©΄ νλ‘μ λ¨κ³μμ κΆνλΆμ¬λ₯Ό ν μ μλ μ΄μ μ΄ μκΈ°κ³ κ°μ²΄λ₯Ό μμ±μν€κ±°λ μ¬μ©νκΈ° λλ¬Έμ λ©λͺ¨λ¦¬λ₯Ό μ μ½ν μ μλ μ΄μ λ μκΈ΄λ€.
μμ μ΄ λ³΄νΈνκ³ μλ κ°μ²΄μ λν μ‘μΈμ€ κΆνμ μ μ΄νλκ²μ΄λ€.
public interface Executor {
public void run(String command) throws Exception;
}
public class ExecutorImpl implements Excutor {
@Override
public void run(String command) throws IOException {
System.out.println("command");
}
}
public class ExecutorProxy implements Excutor {
private Executor exec;
public ExecutorProxy(String user, String passwd) {
private boolean isAdmin;
if ("rrest".equals(user) && "1234".equals(passwd)) {
isAdmin = true;
}
exec = new ExecutorImpl();
}
@Override
public void run(String command) throws Exception {
if (isAdmin) {
exec.run(command);
} else {
throw new Exception("You are not Administrator !!");
}
}
}
public class ProxyPatternTest {
public static void main(String[] args) {
Executor exec = new ExecutorProxy("rrest", "1234");
exec.run("νλ‘μ ν
μ€νΈ");
}
}
β λ°μ½λ μ΄ν° νΌμ¬λ β