码迷,mamicode.com
首页 > 编程语言 > 详细

代理模式原理java实例

时间:2016-08-30 12:10:08      阅读:358      评论:0      收藏:0      [点我收藏+]

标签:

package test;

class ProxyTest {

    public static void main(String[] args) {
        ProxyClass proxy = new ProxyClass();
        proxy.method_1();
        /*
         Console:
             This is ProxyClass.method_1()
            ---Before---
            This is RelClass.method_1()
            ---After----
         */
    }
}

class ProxyClass implements RelClassInf {

    RelClass rel = new RelClass();
    
    @Override
    public void method_1() {
        System.out.println("This is ProxyClass.method_1()");
        System.out.println("---Before---");
        rel.method_1();
        System.out.println("---After----");
    }

    @Override
    public void method_2() {
        System.out.println("This is ProxyClass.method_2()");
        System.out.println("---Before---");
        rel.method_2();
        System.out.println("---After----");
    }
    
}

interface RelClassInf {
    
    void method_1();
    
    void method_2();
}

class RelClass implements RelClassInf {

    @Override
    public void method_1() {
        System.out.println("This is RelClass.method_1()");
    }

    @Override
    public void method_2() {
        System.out.println("This is RelClass.method_2()");
    }
    
}

 

代理模式原理java实例

标签:

原文地址:http://www.cnblogs.com/15ho/p/5821406.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!