码迷,mamicode.com
首页 > 其他好文 > 详细

代理模式简单使用

时间:2019-01-17 10:52:35      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:http   技术   interface   stat   atp   static   准备   oid   int   

package demo2;
interface IEat{
void get();
}
class EatReal implements IEat{
public void get() {
System.out.println("[真实主题类]得到一份食物,然后开始品尝美味");
}
}
class EatProxy implements IEat {
private IEat eat;
public EatProxy(IEat eat) {
this.eat = eat;
}
public void prepare() {
System.out.println("[代理主题类]准备吃");
}
public void get() {
this.prepare();
this.eat.get();
this.clean();
}
public void clean() {
System.out.println("[代理主题类]收拾碗筷");
}

}
public class ProxyTest {
public static void main(String[] args) {
IEat eat = new EatProxy(new EatReal());
eat.get();
}
}

技术分享图片

 

代理模式简单使用

标签:http   技术   interface   stat   atp   static   准备   oid   int   

原文地址:https://www.cnblogs.com/PengeStudy/p/10280886.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!