The Wayback Machine - https://web.archive.org/web/20240129024018/https://www.geeksforgeeks.org/business-delegate-pattern/
Open In App
Related Articles

Business Delegate Pattern

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

The Business Delegate acts as a client-side business abstraction, it provides an abstraction for, and thus hides, the implementation of the business services. It reduces the coupling between presentation-tier clients and the system’s Business services.

UML Diagram Business Delegate Pattern

Image

Design components

  • Business Delegate : A single entry point class for client 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.

Let’s see an example of Business Delegate Pattern.

Java




interface BusinessService
{
    public void doProcessing();
}
 
class OneService implements BusinessService
{
    public void doProcessing()
    {
        System.out.println("Processed Service One");
    }
}
 
class TwoService implements BusinessService
{
    public void doProcessing()
    {
        System.out.println("Processed Service Two");
    }
}
 
class BusinessLookUp
{
    public BusinessService getBusinessService(String serviceType)
    {
        if(serviceType.equalsIgnoreCase("One"))
        {
            return new OneService();
        }
        else
        {
            return new TwoService();
        }
   }
}
 
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();       
    }
}
 
class Client
{
    BusinessDelegate businessService;
 
    public Client(BusinessDelegate businessService)
    {
        this.businessService  = businessService;
    }
 
    public void doTask()
    {       
        businessService.doTask();
    }
}
 
class BusinessDelegatePattern
{
    public static void main(String[] args)
    {
        BusinessDelegate businessDelegate = new BusinessDelegate();
        businessDelegate.setServiceType("One");
 
        Client client = new Client(businessDelegate);
        client.doTask();
 
        businessDelegate.setServiceType("Two");
        client.doTask();
    }
}


Output:

Processed Service One
Processed Service Two

Advantages :

  • Business Delegate reduces coupling between presentation-tier clients and Business services.
  • The Business Delegate hides the underlying implementation details of the Business service.

Disadvantages :

  • Maintenance due the extra layer that increases the number of classes in the application.

If you like GeeksforGeeks and would like to contribute, you can also write an article using

write.geeksforgeeks.org

or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.


Feeling lost in the vast world of System Design? It's time for a transformation! Enroll in our Mastering System Design From Low-Level to High-Level Solutions - Live Course and embark on an exhilarating journey to efficiently master system design concepts and techniques.
What We Offer:

  • Comprehensive Course Coverage
  • Expert Guidance for Efficient Learning
  • Hands-on Experience with Real-world System Design Project
  • Proven Track Record with 100,000+ Successful Enthusiasts

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 30 Oct, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads