Sunday 8 September 2013

Business Delegate Design Pattern - Implementation



Click here to watch in Youtube : https://www.youtube.com/watch?v=qBGmTIRAlBM

Click the below Image to Enlarge
Business Delegate Design Pattern - Implementation - Class Diagram


















BusinessService.java

public interface BusinessService
{
public void doProcessing();
}

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");

}

}

BusinessLookUp.java

public class BusinessLookUp
{
public BusinessService getBusinessService( String serviceType )
{
if( serviceType.equalsIgnoreCase("EJB") )
{
return new EJBService();
}
else if( serviceType.equalsIgnoreCase("JMS") )
{
return new JMSService();
}
return null;
}
}

BusinessDelegate.java

public class BusinessDelegate
{
private BusinessLookUp  lookupService = new BusinessLookUp();
private BusinessService businessService;

public void doTask( String serviceType )
{
businessService = lookupService.getBusinessService(serviceType);

System.out.println(businessService.toString() + " : Got business service object after do the look up");

businessService.doProcessing();
}
}


Client.java

public class Client
{

public static void main( String[] args )
{
BusinessDelegate businessDelegate = new BusinessDelegate();
System.out.println("Invoke the business delegate by passing service type as EJB");
businessDelegate.doTask("EJB");
System.out.println("");
System.out.println("Invoke the business delegate by passing service type as JMS");

businessDelegate.doTask("JMS");

}

}

Output

Invoke the Service Locator by passing service type as EJB
EJBService@42719c : Got business service object after do the look up
Processing task by invoking EJB Service

Invoke the Service Locator by passing service type as JMS
JMSService@119298d : Got business serve object after do the look up
Processing task by invoking JMS Service

1 comment:

  1. Nice blog, Thank you for sharing this helpful content with us. If you are looking free guest posting site for backlinks, Here is an updated list of the best guest blog SEO opportunities. Even newer SEO sites allow paid guest posting, with most of these sites offering free guest writing opportunities.
    For more info visit us:- Guest posting Site List

    ReplyDelete