Java Business Delegate Pattern(业务代表模式)
来源:互联网 发布:怎么在mac上做铃声 编辑:程序博客网 时间:2024/06/06 07:36
Java Business Delegate Pattern(业务代表模式)
业务代表模式(Business Delegate Pattern)用于对表示层和业务层解耦。它基本上是用来减少通信或对表示层代码中的业务层代码的远程查询功能。在业务层中我们有以下实体。
- 客户端(Client) - 表示层代码可以是 JSP、servlet 或 UI java 代码。
- 业务代表(Business Delegate) - 一个为客户端实体提供的入口类,它提供了对业务服务方法的访问。
- 查询服务(LookUp Service) - 查找服务对象负责获取相关的业务实现,并提供业务对象对业务代表对象的访问。
- 业务服务(Business Service) - 业务服务接口。实现了该业务服务的实体类,提供了实际的业务实现逻辑。
- 创建 BusinessService 接口。
/** * 1. 创建 BusinessService 接口。 * @author mazaiting */public interface BusinessService { void doProcessing();}
- 创建实体服务类
/** * 2. 创建实体服务类。 * @author mazaiting */public class EJBService implements BusinessService{ public void doProcessing() { System.out.println("Processing task by invoking EJB Service"); }}/** * 2. 创建实体服务类。 * @author mazaiting */public class JMSService implements BusinessService{ public void doProcessing() { System.out.println("Processing task by invoking JMS Service"); }}
- 创建业务查询服务。
/** * 3. 创建业务查询服务。 * @author mazaiting */public class BusinessLookUp { public BusinessService getBusinessService(String serviceType){ if (serviceType.equalsIgnoreCase("EJB")){ return new EJBService(); } else { return new JMSService(); } }}
- 创建业务代表。
/** * 4. 创建业务代表。 * @author mazaiting */public class BusinessDelegate { private BusinessLookUp lookupService = new BusinessLookUp(); private BusinessService businessService; private String serviceType; public void setServiceType(String serviceType) { this.serviceType = serviceType; } public void doTask(){ businessService = lookupService.getBusinessService(serviceType); businessService.doProcessing(); } }
- 创建客户端。
/** * 5. 创建客户端。 * @author mazaiting */public class Client { BusinessDelegate businessDelegate; public Client(BusinessDelegate businessDelegate){ this.businessDelegate = businessDelegate; } public void doTask(){ businessDelegate.doTask(); }}
- 使用 BusinessDelegate 和 Client 类来演示业务代表模式。
/** * 6. 使用 BusinessDelegate 和 Client 类来演示业务代表模式。 * @author mazaiting */public class Test { public static void main(String[] args) { BusinessDelegate businessDelegate = new BusinessDelegate(); businessDelegate.setServiceType("EJB"); Client client = new Client(businessDelegate); client.doTask(); businessDelegate.setServiceType("JMS"); client.doTask(); } }
7.打印结果
Processing task by invoking EJB ServiceProcessing task by invoking JMS Service
阅读全文
0 0
- Java Business Delegate Pattern(业务代表模式)
- 设计模式学习—业务代表模式(Business Delegate Design Pattern)
- 设计模式学习笔记--业务代表模式
- 设计模式(26)--业务代表模式
- 设计模式【业务代表模式BusinessDelegatePattern】
- JAVA 委派模式(Delegate)
- Java业务代理模式
- Java业务代理模式
- C#代表类型(delegate)
- Java design pattern 设计模式
- Java 策略模式 (Strategy Pattern)
- Java 观察者模式( Observer Pattern)
- JAVA代理模式Proxy Pattern
- java代理模式(Proxy Pattern)
- Java Design Pattern(设计模式)
- Java Factory Pattern(工厂模式)
- Java Prototype Pattern(原型模式)
- Java Adapter Pattern(适配器模式)
- Java Strategy Pattern(策略模式)
- Java Template Pattern(模板模式)
- Java Visitor Pattern(访问者模式)
- Jcenter 依赖完整版
- Java MVC Pattern(MVC 模式)
- Java Business Delegate Pattern(业务代表模式)
- Java Composite Entity Pattern(组合实体模式)
- Java Data Access Object Pattern(数据访问对象模式)
- Java 邮件(问题解决)
- Java 邮件(JavaMail)
- Java Pinyin4j(汉字转拼音)
- Java Front Controller Pattern(前端控制器模式)
- Java Intercepting Filter Pattern(拦截过滤器)
- Java Service Locator Pattern(服务器定位模式)