#89 Finished the example code
This commit is contained in:
parent
731f37723a
commit
61573e9ef2
@ -3,6 +3,14 @@ package com.iluwatar;
|
||||
public class App {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello World!");
|
||||
|
||||
BusinessDelegate businessDelegate = new BusinessDelegate();
|
||||
businessDelegate.setServiceType(ServiceType.EJB);
|
||||
|
||||
Client client = new Client(businessDelegate);
|
||||
client.doTask();
|
||||
|
||||
businessDelegate.setServiceType(ServiceType.JMS);
|
||||
client.doTask();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
package com.iluwatar;
|
||||
|
||||
public class BusinessDelegate {
|
||||
|
||||
private BusinessLookup lookupService = new BusinessLookup();
|
||||
private BusinessService businessService;
|
||||
private ServiceType serviceType;
|
||||
|
||||
public void setServiceType(ServiceType serviceType) {
|
||||
this.serviceType = serviceType;
|
||||
}
|
||||
|
||||
public void doTask() {
|
||||
businessService = lookupService.getBusinessService(serviceType);
|
||||
businessService.doProcessing();
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.iluwatar;
|
||||
|
||||
public class BusinessLookup {
|
||||
|
||||
public BusinessService getBusinessService(ServiceType serviceType) {
|
||||
if (serviceType.equals(ServiceType.EJB)) {
|
||||
return new EjbService();
|
||||
} else {
|
||||
return new JmsService();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package com.iluwatar;
|
||||
|
||||
public interface BusinessService {
|
||||
|
||||
void doProcessing();
|
||||
}
|
14
business-delegate/src/main/java/com/iluwatar/Client.java
Normal file
14
business-delegate/src/main/java/com/iluwatar/Client.java
Normal file
@ -0,0 +1,14 @@
|
||||
package com.iluwatar;
|
||||
|
||||
public class Client {
|
||||
|
||||
private BusinessDelegate businessDelegate;
|
||||
|
||||
public Client(BusinessDelegate businessDelegate) {
|
||||
this.businessDelegate = businessDelegate;
|
||||
}
|
||||
|
||||
public void doTask() {
|
||||
businessDelegate.doTask();
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.iluwatar;
|
||||
|
||||
public class EjbService implements BusinessService {
|
||||
|
||||
@Override
|
||||
public void doProcessing() {
|
||||
System.out.println("EjbService is now processing");
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.iluwatar;
|
||||
|
||||
public class JmsService implements BusinessService {
|
||||
|
||||
@Override
|
||||
public void doProcessing() {
|
||||
System.out.println("JmsService is now processing");
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package com.iluwatar;
|
||||
|
||||
public enum ServiceType {
|
||||
|
||||
EJB, JMS;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user