6.29. Business representative model

发布时间 : 2025-10-25 13:34:19 UTC      

Page Views: 9 views

The Business Representative pattern (Business Delegate Pattern) is used to decouple the presentation layer from the business layer. It is basically used to reduce communication or remote query capabilities for business layer code in the presentation layer code. We have the following entities in the business layer.

  • 客户端(Client) The presentation layer code can be JSP, servlet, or UI java code.

  • 业务代表(Business Delegate) -an entry class for client entities that provides access to business service methods.

  • 查询服务(LookUp Service) -the lookup service object is responsible for obtaining the relevant business implementation and providing access to the business representative object.

  • 业务服务(Business Service) -Business service interface. The entity class of the business service is implemented and the actual business implementation logic is provided.

6.29.1. Realize

We will create Client BusinessDelegate BusinessService LookUpService JMSService And EJBService To represent the various entities in the business representative model.

BusinessDelegatePatternDemo Class usage BusinessDelegate And Client To demonstrate the use of the business representative model.

业务代表模式的 UML 图

6.29.2. Step 1

Create a BusinessService interface.

BusinessService.java

publicinterfaceBusinessService{publicvoiddoProcessing();} 

6.29.3. Step 2

Create an entity service class.

EJBService.java

publicclassEJBServiceimplementsBusinessService{@OverridepublicvoiddoProcessing(){System.out.println("Processing task by invoking EJB Service");}} 

JMSService.java

publicclassJMSServiceimplementsBusinessService{@OverridepublicvoiddoProcessing(){System.out.println("Processing task by invoking JMS Service");}} 

6.29.4. Step 3

Create a business query service.

BusinessLookUp.java

publicclassBusinessLookUp{publicBusinessServicegetBusinessService(StringserviceType){if(serviceType.equalsIgnoreCase("EJB")){returnnewEJBService();}else{returnnewJMSService();}}} 

6.29.5. Step 4

Create a business representative.

BusinessDelegate.java

publicclassBusinessDelegate{privateBusinessLookUplookupService=newBusinessLookUp();privateBusinessServicebusinessService;privateStringserviceType;publicvoidsetServiceType(StringserviceType){this.serviceType=serviceType;}publicvoiddoTask(){businessService=lookupService.getBusinessService(serviceType);businessService.doProcessing();}} 

6.29.6. Step 5

Create a client.

Client.java

publicclassClient{BusinessDelegatebusinessService;publicClient(BusinessDelegatebusinessService){this.businessService=businessService;}publicvoiddoTask(){businessService.doTask();}} 

6.29.7. Step 6

Use the BusinessDelegate and Client classes to demonstrate the business representative pattern.

BusinessDelegatePatternDemo.java

publicclassBusinessDelegatePatternDemo{publicstaticvoidmain(String[]args){BusinessDelegatebusinessDelegate=newBusinessDelegate();businessDelegate.setServiceType("EJB");Clientclient=newClient(businessDelegate);client.doTask();businessDelegate.setServiceType("JMS");client.doTask();}} 

6.29.8. Step 7

Execute the program and output the result:

Processing task by invoking EJB Service Processing task by invoking JMS Service 
《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。