The best Agent mode Tutorial In 2024, In this tutorial you can learn achieve,step 1,Step 2,Step 3,Step 4,Step 5,Step 6,Step 7,
Agent mode (Business Delegate Pattern) for the presentation layer and the business layer decoupling. It is basically used to reduce the communication or presentation layer code business layer code remote query capabilities. In the business layer, we have the following entities.
We will create theClient, BusinessDelegate, BusinessService, LookUpService,JMSService andEJBServiceto represent the business model on behalf of various entities.
BusinessDelegatePatternDemo,our demonstration class to demonstrate the use ofBusinessDelegateandClientagent mode usage.
Create BusinessService interface.
BusinessService.java
public interface BusinessService { public void doProcessing (); }
Create entity class service.
EJBService.java
public class EJBService implements BusinessService { @Override public void doProcessing () { System.out.println ( "Processing task by invoking EJB Service"); } }
JMSService.java
public class JMSService implements BusinessService { @Override public void doProcessing () { System.out.println ( "Processing task by invoking JMS Service"); } }
Create a business inquiry service.
BusinessLookUp.java
public class BusinessLookUp { public BusinessService getBusinessService (String serviceType) { if (serviceType.equalsIgnoreCase ( "EJB")) { return new EJBService (); } Else { return new JMSService (); } } }
Create a business representative.
BusinessDelegate.java
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 (); } }
Create a client.
Student.java
public class Client { BusinessDelegate businessService; public Client (BusinessDelegate businessService) { this.businessService = businessService; } public void doTask () { businessService.doTask (); } }
Use BusinessDelegate and Client class to demonstrate the agent mode.
BusinessDelegatePatternDemo.java
public class BusinessDelegatePatternDemo { 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 (); } }
Verify output.
Processing task by invoking EJB Service Processing task by invoking JMS Service