静态代理
Posted snailsrunning
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了静态代理相关的知识,希望对你有一定的参考价值。
代码如下
package day19;
interface ClothFactory{
public void show();
}
//被代理类;
class NikeFactory implements ClothFactory{
@Override
public void show() {
// TODO Auto-generated method stub
System.out.println("生产Nike衣服的工厂!");
}
}
//代理类;
class ProxyFactory implements ClothFactory{
private ClothFactory factory ;
public ProxyFactory(ClothFactory factory) {
super();
this.factory = factory;
}
@Override
public void show() {
// TODO Auto-generated method stub
factory.show(); //调用真正的被代理类的方法;
}
}
public class StaticProxy {
public static void main(String[] args) {
NikeFactory realFactory = new NikeFactory();
ProxyFactory proxyFactory = new ProxyFactory(realFactory);
proxyFactory.show();//实际是调用了NikeFactory的方法;
}
}
运行结果
以上是关于静态代理的主要内容,如果未能解决你的问题,请参考以下文章