package com.maom.design.D_12_Proxy;
/**
* @Title: D_12_Proxy
* @Description: 12_代理模式
* @Author maohb
* @Version 1.0
*/
public class D_12_Proxy {
public static void main(String[] args) {
ProxySubject proxySubject = new ProxySubject();
proxySubject.sailBook();
}
}
interface Subject {
public void sailBook();
}
class RealSubject implements Subject {
public void sailBook() {
System.out.println("卖书");
}
}
/** 代理 */
class ProxySubject implements Subject {
private RealSubject realSubject;
public void sailBook() {
dazhe();
if (realSubject == null) {
realSubject = new RealSubject();
}
realSubject.sailBook();
give();
}
public void dazhe() {
System.out.println("打折");
}
public void give() {
System.out.println("赠送代金券");
}
}
设计模式笔记_12_代理模式
最新推荐文章于 2024-09-08 21:56:57 发布