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

No comments:

Post a Comment

Google+ Followers

Google+ Badge