File tree Expand file tree Collapse file tree 5 files changed +57
-0
lines changed
src/com/anxpp/designpattern/proxy Expand file tree Collapse file tree 5 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .anxpp .designpattern .proxy ;
2+ //抽象对象
3+ public interface AbstractObject {
4+ void method1 ();
5+ int method2 ();
6+ void method3 ();
7+ }
Original file line number Diff line number Diff line change 1+ package com .anxpp .designpattern .proxy ;
2+ //代理对象
3+ public class ProxyObject implements AbstractObject {
4+ AbstractObject object = new TargetObject ();
5+ @ Override
6+ public void method1 () {
7+ object .method1 ();
8+ }
9+ @ Override
10+ public int method2 () {
11+ return object .method2 ();
12+ }
13+ @ Override
14+ public void method3 () {
15+ System .out .println ("调用目标对象前的操作" );
16+ object .method3 ();
17+ System .out .println ("调用目标对象后的操作" );
18+ }
19+ }
Original file line number Diff line number Diff line change 1+ package com .anxpp .designpattern .proxy ;
2+ //具体对象
3+ public class TargetObject implements AbstractObject {
4+ @ Override
5+ public void method1 () {
6+ System .out .println ("具体对象的方法1" );
7+ }
8+ @ Override
9+ public int method2 () {
10+ System .out .println ("具体对象的方法2" );
11+ return 0 ;
12+ }
13+ @ Override
14+ public void method3 () {
15+ System .out .println ("具体对象的方法3" );
16+ }
17+ }
Original file line number Diff line number Diff line change 1+ package com .anxpp .designpattern .proxy ;
2+ public class TestUse {
3+ public static void main (String args []){
4+ AbstractObject obj = new ProxyObject ();
5+ obj .method1 ();
6+ obj .method2 ();
7+ obj .method3 ();
8+ }
9+ }
Original file line number Diff line number Diff line change 1+ /**
2+ * @author Administrator
3+ * 代理模式
4+ */
5+ package com .anxpp .designpattern .proxy ;
You can’t perform that action at this time.
0 commit comments