Reformat business-delegate, callback, chain, command, composite, dao, decorator & dependency-injection patterns.
This commit is contained in:
@ -2,34 +2,36 @@ package com.iluwatar.business.delegate;
|
||||
|
||||
/**
|
||||
*
|
||||
* The Business Delegate pattern adds an abstraction layer between the presentation and business tiers.
|
||||
* By using the pattern we gain loose coupling between the tiers. The Business Delegate encapsulates
|
||||
* knowledge about how to locate, connect to, and interact with the business objects that make up
|
||||
* the application.
|
||||
* The Business Delegate pattern adds an abstraction layer between the presentation and business
|
||||
* tiers. By using the pattern we gain loose coupling between the tiers. The Business Delegate
|
||||
* encapsulates knowledge about how to locate, connect to, and interact with the business objects
|
||||
* that make up the application.
|
||||
* <p>
|
||||
* Some of the services the Business Delegate uses are instantiated directly, and some can be retrieved
|
||||
* through service lookups. The Business Delegate itself may contain business logic too potentially tying
|
||||
* together multiple service calls, exception handling, retrying etc.
|
||||
* Some of the services the Business Delegate uses are instantiated directly, and some can be
|
||||
* retrieved through service lookups. The Business Delegate itself may contain business logic too
|
||||
* potentially tying together multiple service calls, exception handling, retrying etc.
|
||||
* <p>
|
||||
* In this example the client ({@link Client}) utilizes a business delegate ({@link BusinessDelegate}) to execute a task.
|
||||
* The Business Delegate then selects the appropriate service and makes the service call.
|
||||
* In this example the client ({@link Client}) utilizes a business delegate (
|
||||
* {@link BusinessDelegate}) to execute a task. The Business Delegate then selects the appropriate
|
||||
* service and makes the service call.
|
||||
*
|
||||
*/
|
||||
public class App {
|
||||
|
||||
/**
|
||||
* Program entry point
|
||||
* @param args command line args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
BusinessDelegate businessDelegate = new BusinessDelegate();
|
||||
businessDelegate.setServiceType(ServiceType.EJB);
|
||||
|
||||
Client client = new Client(businessDelegate);
|
||||
client.doTask();
|
||||
/**
|
||||
* Program entry point
|
||||
*
|
||||
* @param args command line args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
businessDelegate.setServiceType(ServiceType.JMS);
|
||||
client.doTask();
|
||||
}
|
||||
BusinessDelegate businessDelegate = new BusinessDelegate();
|
||||
businessDelegate.setServiceType(ServiceType.EJB);
|
||||
|
||||
Client client = new Client(businessDelegate);
|
||||
client.doTask();
|
||||
|
||||
businessDelegate.setServiceType(ServiceType.JMS);
|
||||
client.doTask();
|
||||
}
|
||||
}
|
||||
|
@ -6,17 +6,17 @@ package com.iluwatar.business.delegate;
|
||||
*
|
||||
*/
|
||||
public class BusinessDelegate {
|
||||
|
||||
private BusinessLookup lookupService = new BusinessLookup();
|
||||
private BusinessService businessService;
|
||||
private ServiceType serviceType;
|
||||
|
||||
public void setServiceType(ServiceType serviceType) {
|
||||
this.serviceType = serviceType;
|
||||
}
|
||||
private BusinessLookup lookupService = new BusinessLookup();
|
||||
private BusinessService businessService;
|
||||
private ServiceType serviceType;
|
||||
|
||||
public void doTask() {
|
||||
businessService = lookupService.getBusinessService(serviceType);
|
||||
businessService.doProcessing();
|
||||
}
|
||||
public void setServiceType(ServiceType serviceType) {
|
||||
this.serviceType = serviceType;
|
||||
}
|
||||
|
||||
public void doTask() {
|
||||
businessService = lookupService.getBusinessService(serviceType);
|
||||
businessService.doProcessing();
|
||||
}
|
||||
}
|
||||
|
@ -7,11 +7,11 @@ package com.iluwatar.business.delegate;
|
||||
*/
|
||||
public class BusinessLookup {
|
||||
|
||||
public BusinessService getBusinessService(ServiceType serviceType) {
|
||||
if (serviceType.equals(ServiceType.EJB)) {
|
||||
return new EjbService();
|
||||
} else {
|
||||
return new JmsService();
|
||||
}
|
||||
}
|
||||
public BusinessService getBusinessService(ServiceType serviceType) {
|
||||
if (serviceType.equals(ServiceType.EJB)) {
|
||||
return new EjbService();
|
||||
} else {
|
||||
return new JmsService();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,5 +7,5 @@ package com.iluwatar.business.delegate;
|
||||
*/
|
||||
public interface BusinessService {
|
||||
|
||||
void doProcessing();
|
||||
void doProcessing();
|
||||
}
|
||||
|
@ -7,13 +7,13 @@ package com.iluwatar.business.delegate;
|
||||
*/
|
||||
public class Client {
|
||||
|
||||
private BusinessDelegate businessDelegate;
|
||||
private BusinessDelegate businessDelegate;
|
||||
|
||||
public Client(BusinessDelegate businessDelegate) {
|
||||
this.businessDelegate = businessDelegate;
|
||||
}
|
||||
public Client(BusinessDelegate businessDelegate) {
|
||||
this.businessDelegate = businessDelegate;
|
||||
}
|
||||
|
||||
public void doTask() {
|
||||
businessDelegate.doTask();
|
||||
}
|
||||
public void doTask() {
|
||||
businessDelegate.doTask();
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ package com.iluwatar.business.delegate;
|
||||
*/
|
||||
public class EjbService implements BusinessService {
|
||||
|
||||
@Override
|
||||
public void doProcessing() {
|
||||
System.out.println("EjbService is now processing");
|
||||
}
|
||||
@Override
|
||||
public void doProcessing() {
|
||||
System.out.println("EjbService is now processing");
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ package com.iluwatar.business.delegate;
|
||||
*/
|
||||
public class JmsService implements BusinessService {
|
||||
|
||||
@Override
|
||||
public void doProcessing() {
|
||||
System.out.println("JmsService is now processing");
|
||||
}
|
||||
@Override
|
||||
public void doProcessing() {
|
||||
System.out.println("JmsService is now processing");
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,6 @@ package com.iluwatar.business.delegate;
|
||||
*
|
||||
*/
|
||||
public enum ServiceType {
|
||||
|
||||
EJB, JMS;
|
||||
|
||||
EJB, JMS;
|
||||
}
|
||||
|
@ -10,10 +10,10 @@ import com.iluwatar.business.delegate.App;
|
||||
*
|
||||
*/
|
||||
public class AppTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
String[] args = {};
|
||||
App.main(args);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
String[] args = {};
|
||||
App.main(args);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user