package com.mystudy.spring;
/**
* 普通的静态代理demo
* @author Liang Wenjie
* @version 1.00
* @time 2019/9/5 0005 下午 6:14
*/
public class ProxyPattern {
public static void main(String[] args) {
Proxy proxy = new Proxy();
proxy.rent();
}
}
//定义一个接口,让代理对象和被代理对象都有相同的接口
interface Rent{
//出租方法
void rent();
}
//创建两个对象,都实现相同的接口
class Target implements Rent{
@Override
public void rent() {
System.out.println("我是房东,我有房子出租");
}
}
//代理对象
class Proxy implements Rent{
Rent rent = new Target();
@Override
public void rent() {
System.out.println("我是中介,我帮忙代理出租 房子");
rent.rent();
System.out.println("我替房东收租");
}
}
1135

被折叠的 条评论
为什么被折叠?



