代理模式之静态代理代码

star2017 1年前 ⋅ 1809 阅读
package com.debuggg.java.exer2;

public class StaticProxyTest {

    public static void main(String[] args) {
        ClothFactory clothFactory = new ClothFactoryImpl();
        ProxyClothFactory proxyClothFactory = new ProxyClothFactory(clothFactory);
        proxyClothFactory.produceCloth();
    }

}

interface ClothFactory{
    void produceCloth();
}

/**
 * 作者 ZYL
 * 功能描述 : 代理类
 * 特点:编译期间,代理类和被代理类都被确定了
 * 日期 2020-03-01 11:26
 * 参数 null
 * 返回值
 */
class ProxyClothFactory implements ClothFactory{
    ClothFactory clothFactory;

    public ProxyClothFactory(ClothFactory clothFactory) {
        this.clothFactory = clothFactory;
    }

    @Override
    public void produceCloth() {
        System.out.println("代理工厂准备工作");
        clothFactory.produceCloth();
        System.out.println("代理工厂做一些后续的收尾工作");
    }
}

class ClothFactoryImpl implements ClothFactory{

    @Override
    public void produceCloth() {
        System.out.println("Nike工厂生产一批工作服");
    }
}
更多内容请访问:IT源点

相关文章推荐

全部评论: 0

    我有话说: