首页 > 编程语言 > 详细

JAVA学习--反射之静态代理模式

时间:2015-02-04 21:34:46      阅读:378      评论:0      收藏:0      [点我收藏+]
 1 //静态代理模式
 2 //接口
 3 interface ClothFactory{
 4     void productCloth();
 5 }
 6 //被代理类
 7 class NikeClothFactory implements ClothFactory{
 8 
 9     @Override
10     public void productCloth() {
11         System.out.println("Nike工厂生产一批衣服");
12     }    
13 }
14 //代理类
15 class ProxyFactory implements ClothFactory{
16     ClothFactory cf;
17     //创建代理类的对象时,实际传入一个被代理类的对象
18     public ProxyFactory(ClothFactory cf){
19         this.cf = cf;
20     }
21     
22     @Override
23     public void productCloth() {
24         System.out.println("代理类开始执行,收代理费$1000");
25         cf.productCloth();
26     }
27     
28 }
29 
30 public class TestClothProduct {
31     public static void main(String[] args) {
32         NikeClothFactory nike = new NikeClothFactory();//创建被代理类的对象
33         ProxyFactory proxy = new ProxyFactory(nike);//创建代理类的对象
34         proxy.productCloth();
35     }
36 }

 

JAVA学习--反射之静态代理模式

原文:http://www.cnblogs.com/zhangfan94/p/4273240.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!