JAVA学習--インタフェースの応用:エージェントモード
4145 ワード
1 public class TestProxy {
2 public static void main(String[] args) {
3 Object obj = new ProxyObject();
4 obj.action();
5 }
6 }
7
8 interface Object{
9 void action();
10 }
11 //
12 class ProxyObject implements Object{
13 Object obj;
14
15 public ProxyObject(){
16 System.out.println(" ");
17 obj = new ObjctImpl();
18 }
19
20 public void action(){
21 System.out.println(" ");
22 obj.action();
23 System.out.println(" ");
24 }
25 }
26 //
27 class ObjctImpl implements Object{
28
29 @Override
30 public void action() {
31 System.out.println("===== ======");
32 System.out.println("===== ======");
33 System.out.println("===== ======");
34
35 }
36
37 }