• 代理模式


    package com.java.exec2;
    
    /**
     * Created by zhangyanana    on 2017/3/16.
     */
    //静态代理模式
    //接口
    interface ClothFactory {
        void productCloth();
    }
    
    //被代理类
    class NikeClothFactory implements ClothFactory {
    
        @Override
        public void productCloth() {
            System.out.println("Nike工厂生产一批衣服");
        }
    }
    
    //代理类
    class ProxyFactory implements ClothFactory {
        ClothFactory cf;
        //创建代理类对象时,实际传入一个被代理类的对象
        public ProxyFactory(ClothFactory cf) {
            this.cf = cf;
        }
    
        @Override
        public void productCloth() {
            System.out.println("代理类开始执行,收代理费$1000");
            cf.productCloth();
        }
    }
    
    public class TestClothProduct {
        public static void main(String[] args) {
            NikeClothFactory ncf = new NikeClothFactory();//创建被代理类的对象
            ProxyFactory pf = new ProxyFactory(ncf);//创建代理类的对象
            pf.productCloth();
        }
    }
  • 相关阅读:
    ContextMenuStrip 类
    ToolStripMenuItem
    ubuntu16.04下安装cuda8.0
    插入排序
    Python *args **kw
    python面向对象编程
    0/1背包问题(回溯法)
    Python decorator装饰器
    Python 函数式编程
    分治策略(求解递归式的方法)
  • 原文地址:https://www.cnblogs.com/zhyn-BeHard/p/6559395.html
Copyright © 2020-2023  润新知