- Transfer Object Pattern
- Service Locator Pattern
- Intercepting Filter Pattern
- Front Controller Pattern
- Data Access Object Pattern
- Composite Entity Pattern
- Business Delegate Pattern
- Design Patterns - MVC Pattern
- Design Patterns - Visitor Pattern
- Design Patterns - Template Pattern
- Design Patterns - Strategy Pattern
- Design Patterns - Null Object Pattern
- Design Patterns - State Pattern
- Design Patterns - Observer Pattern
- Design Patterns - Memento Pattern
- Design Patterns - Mediator Pattern
- Design Patterns - Iterator Pattern
- Design Patterns - Interpreter Pattern
- Design Patterns - Command Pattern
- Chain of Responsibility Pattern
- Design Patterns - Proxy Pattern
- Design Patterns - Flyweight Pattern
- Design Patterns - Facade Pattern
- Design Patterns - Decorator Pattern
- Design Patterns - Composite Pattern
- Design Patterns - Filter Pattern
- Design Patterns - Bridge Pattern
- Design Patterns - Adapter Pattern
- Design Patterns - Prototype Pattern
- Design Patterns - Builder Pattern
- Design Patterns - Singleton Pattern
- Abstract Factory Pattern
- Design Patterns - Factory Pattern
- Design Patterns - Overview
- Design Patterns - Home
Design Patterns Resources
- Design Patterns - Discussion
- Design Patterns - Useful Resources
- Design Patterns - Quick Guide
- Design Patterns - Questions/Answers
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Design Patterns - Business Delegate Pattern
Business Delegate Pattern is used to decouple presentation tier and business tier. It is basically use to reduce communication or remote lookup functionapty to business tier code in presentation tier code. In business tier we have following entities.
Cpent - Presentation tier code may be JSP, servlet or UI java code.
Business Delegate - A single entry point class for cpent entities to provide access to Business Service methods.
LookUp Service - Lookup service object is responsible to get relative business implementation and provide business object access to business delegate object.
Business Service - Business Service interface. Concrete classes implement this business service to provide actual business implementation logic.
Implementation
We are going to create a Cpent, BusinessDelegate, BusinessService, LookUpService, JMSService and EJBService representing various entities of Business Delegate patterns.
BusinessDelegatePatternDemo, our demo class, will use BusinessDelegate and Cpent to demonstrate use of Business Delegate pattern.
Step 1
Create BusinessService Interface.
BusinessService.java
pubpc interface BusinessService { pubpc void doProcessing(); }
Step 2
Create concrete Service classes.
EJBService.java
pubpc class EJBService implements BusinessService { @Override pubpc void doProcessing() { System.out.println("Processing task by invoking EJB Service"); } }
JMSService.java
pubpc class JMSService implements BusinessService { @Override pubpc void doProcessing() { System.out.println("Processing task by invoking JMS Service"); } }
Step 3
Create Business Lookup Service.
BusinessLookUp.java
pubpc class BusinessLookUp { pubpc BusinessService getBusinessService(String serviceType){ if(serviceType.equalsIgnoreCase("EJB")){ return new EJBService(); } else { return new JMSService(); } } }
Step 4
Create Business Delegate.
BusinessDelegate.java
pubpc class BusinessDelegate { private BusinessLookUp lookupService = new BusinessLookUp(); private BusinessService businessService; private String serviceType; pubpc void setServiceType(String serviceType){ this.serviceType = serviceType; } pubpc void doTask(){ businessService = lookupService.getBusinessService(serviceType); businessService.doProcessing(); } }
Step 5
Create Cpent.
Cpent.java
pubpc class Cpent { BusinessDelegate businessService; pubpc Cpent(BusinessDelegate businessService){ this.businessService = businessService; } pubpc void doTask(){ businessService.doTask(); } }
Step 6
Use BusinessDelegate and Cpent classes to demonstrate Business Delegate pattern.
BusinessDelegatePatternDemo.java
pubpc class BusinessDelegatePatternDemo { pubpc static void main(String[] args) { BusinessDelegate businessDelegate = new BusinessDelegate(); businessDelegate.setServiceType("EJB"); Cpent cpent = new Cpent(businessDelegate); cpent.doTask(); businessDelegate.setServiceType("JMS"); cpent.doTask(); } }
Step 7
Verify the output.
Processing task by invoking EJB Service Processing task by invoking JMS ServiceAdvertisements