Skip to content

Commit 61573e9

Browse files
committed
iluwatar#89 Finished the example code
1 parent 731f377 commit 61573e9

8 files changed

Lines changed: 82 additions & 1 deletion

File tree

business-delegate/src/main/java/com/iluwatar/App.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
public class App {
44

55
public static void main(String[] args) {
6-
System.out.println("Hello World!");
6+
7+
BusinessDelegate businessDelegate = new BusinessDelegate();
8+
businessDelegate.setServiceType(ServiceType.EJB);
9+
10+
Client client = new Client(businessDelegate);
11+
client.doTask();
12+
13+
businessDelegate.setServiceType(ServiceType.JMS);
14+
client.doTask();
715
}
816
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.iluwatar;
2+
3+
public class BusinessDelegate {
4+
5+
private BusinessLookup lookupService = new BusinessLookup();
6+
private BusinessService businessService;
7+
private ServiceType serviceType;
8+
9+
public void setServiceType(ServiceType serviceType) {
10+
this.serviceType = serviceType;
11+
}
12+
13+
public void doTask() {
14+
businessService = lookupService.getBusinessService(serviceType);
15+
businessService.doProcessing();
16+
}
17+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.iluwatar;
2+
3+
public class BusinessLookup {
4+
5+
public BusinessService getBusinessService(ServiceType serviceType) {
6+
if (serviceType.equals(ServiceType.EJB)) {
7+
return new EjbService();
8+
} else {
9+
return new JmsService();
10+
}
11+
}
12+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.iluwatar;
2+
3+
public interface BusinessService {
4+
5+
void doProcessing();
6+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.iluwatar;
2+
3+
public class Client {
4+
5+
private BusinessDelegate businessDelegate;
6+
7+
public Client(BusinessDelegate businessDelegate) {
8+
this.businessDelegate = businessDelegate;
9+
}
10+
11+
public void doTask() {
12+
businessDelegate.doTask();
13+
}
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.iluwatar;
2+
3+
public class EjbService implements BusinessService {
4+
5+
@Override
6+
public void doProcessing() {
7+
System.out.println("EjbService is now processing");
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.iluwatar;
2+
3+
public class JmsService implements BusinessService {
4+
5+
@Override
6+
public void doProcessing() {
7+
System.out.println("JmsService is now processing");
8+
}
9+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.iluwatar;
2+
3+
public enum ServiceType {
4+
5+
EJB, JMS;
6+
}

0 commit comments

Comments
 (0)