博主前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住也分享一下给大家,
👉点击跳转到网站
代码如下:
package www.demo10;
interface ClothFactory{
void productionCloth();
}
//代理类
class Agency implements ClothFactory{
private ClothFactory clothFactory;
public Agency(ClothFactory clothFactory){
this.clothFactory =clothFactory;
}
@Override
public void productionCloth() {
System.out.println("代理类");
clothFactory.productionCloth();
System.out.println("代理类。。。。。");
}
}
//被代理类
class ByProxy implements ClothFactory{
@Override
public void productionCloth() {
System.out.println("Nike最近在生产一批运动服");
}
}
public class StaticProxyTest {
public static void main(String[] args) {
ByProxy byProxy = new ByProxy();
Agency agency = new Agency(byProxy);
agency.productionCloth();
}
}
结果如下:
代理类
Nike最近在生产一批运动服
代理类。。。。。