Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 449340b

Browse filesBrowse files
committed
Reformat business-delegate, callback, chain, command, composite, dao, decorator & dependency-injection patterns.
1 parent 3af06a3 commit 449340b
Copy full SHA for 449340b

54 files changed

+718-720Lines changed: 718 additions & 720 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: business-delegate/src/main/java/com/iluwatar/business/delegate/App.java
+25-23Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,36 @@
22

33
/**
44
*
5-
* The Business Delegate pattern adds an abstraction layer between the presentation and business tiers.
6-
* By using the pattern we gain loose coupling between the tiers. The Business Delegate encapsulates
7-
* knowledge about how to locate, connect to, and interact with the business objects that make up
8-
* the application.
5+
* The Business Delegate pattern adds an abstraction layer between the presentation and business
6+
* tiers. By using the pattern we gain loose coupling between the tiers. The Business Delegate
7+
* encapsulates knowledge about how to locate, connect to, and interact with the business objects
8+
* that make up the application.
99
* <p>
10-
* Some of the services the Business Delegate uses are instantiated directly, and some can be retrieved
11-
* through service lookups. The Business Delegate itself may contain business logic too potentially tying
12-
* together multiple service calls, exception handling, retrying etc.
10+
* Some of the services the Business Delegate uses are instantiated directly, and some can be
11+
* retrieved through service lookups. The Business Delegate itself may contain business logic too
12+
* potentially tying together multiple service calls, exception handling, retrying etc.
1313
* <p>
14-
* In this example the client ({@link Client}) utilizes a business delegate ({@link BusinessDelegate}) to execute a task.
15-
* The Business Delegate then selects the appropriate service and makes the service call.
14+
* In this example the client ({@link Client}) utilizes a business delegate (
15+
* {@link BusinessDelegate}) to execute a task. The Business Delegate then selects the appropriate
16+
* service and makes the service call.
1617
*
1718
*/
1819
public class App {
19-
20-
/**
21-
* Program entry point
22-
* @param args command line args
23-
*/
24-
public static void main(String[] args) {
25-
26-
BusinessDelegate businessDelegate = new BusinessDelegate();
27-
businessDelegate.setServiceType(ServiceType.EJB);
2820

29-
Client client = new Client(businessDelegate);
30-
client.doTask();
21+
/**
22+
* Program entry point
23+
*
24+
* @param args command line args
25+
*/
26+
public static void main(String[] args) {
3127

32-
businessDelegate.setServiceType(ServiceType.JMS);
33-
client.doTask();
34-
}
28+
BusinessDelegate businessDelegate = new BusinessDelegate();
29+
businessDelegate.setServiceType(ServiceType.EJB);
30+
31+
Client client = new Client(businessDelegate);
32+
client.doTask();
33+
34+
businessDelegate.setServiceType(ServiceType.JMS);
35+
client.doTask();
36+
}
3537
}
Collapse file

‎business-delegate/src/main/java/com/iluwatar/business/delegate/BusinessDelegate.java‎

Copy file name to clipboardExpand all lines: business-delegate/src/main/java/com/iluwatar/business/delegate/BusinessDelegate.java
+11-11Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
*
77
*/
88
public class BusinessDelegate {
9-
10-
private BusinessLookup lookupService = new BusinessLookup();
11-
private BusinessService businessService;
12-
private ServiceType serviceType;
139

14-
public void setServiceType(ServiceType serviceType) {
15-
this.serviceType = serviceType;
16-
}
10+
private BusinessLookup lookupService = new BusinessLookup();
11+
private BusinessService businessService;
12+
private ServiceType serviceType;
1713

18-
public void doTask() {
19-
businessService = lookupService.getBusinessService(serviceType);
20-
businessService.doProcessing();
21-
}
14+
public void setServiceType(ServiceType serviceType) {
15+
this.serviceType = serviceType;
16+
}
17+
18+
public void doTask() {
19+
businessService = lookupService.getBusinessService(serviceType);
20+
businessService.doProcessing();
21+
}
2222
}
Collapse file

‎business-delegate/src/main/java/com/iluwatar/business/delegate/BusinessLookup.java‎

Copy file name to clipboardExpand all lines: business-delegate/src/main/java/com/iluwatar/business/delegate/BusinessLookup.java
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
*/
88
public class BusinessLookup {
99

10-
public BusinessService getBusinessService(ServiceType serviceType) {
11-
if (serviceType.equals(ServiceType.EJB)) {
12-
return new EjbService();
13-
} else {
14-
return new JmsService();
15-
}
16-
}
10+
public BusinessService getBusinessService(ServiceType serviceType) {
11+
if (serviceType.equals(ServiceType.EJB)) {
12+
return new EjbService();
13+
} else {
14+
return new JmsService();
15+
}
16+
}
1717
}
Collapse file

‎business-delegate/src/main/java/com/iluwatar/business/delegate/BusinessService.java‎

Copy file name to clipboardExpand all lines: business-delegate/src/main/java/com/iluwatar/business/delegate/BusinessService.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
*/
88
public interface BusinessService {
99

10-
void doProcessing();
10+
void doProcessing();
1111
}
Collapse file

‎business-delegate/src/main/java/com/iluwatar/business/delegate/Client.java‎

Copy file name to clipboardExpand all lines: business-delegate/src/main/java/com/iluwatar/business/delegate/Client.java
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
*/
88
public class Client {
99

10-
private BusinessDelegate businessDelegate;
10+
private BusinessDelegate businessDelegate;
1111

12-
public Client(BusinessDelegate businessDelegate) {
13-
this.businessDelegate = businessDelegate;
14-
}
12+
public Client(BusinessDelegate businessDelegate) {
13+
this.businessDelegate = businessDelegate;
14+
}
1515

16-
public void doTask() {
17-
businessDelegate.doTask();
18-
}
16+
public void doTask() {
17+
businessDelegate.doTask();
18+
}
1919
}
Collapse file

‎business-delegate/src/main/java/com/iluwatar/business/delegate/EjbService.java‎

Copy file name to clipboardExpand all lines: business-delegate/src/main/java/com/iluwatar/business/delegate/EjbService.java
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*/
88
public class EjbService implements BusinessService {
99

10-
@Override
11-
public void doProcessing() {
12-
System.out.println("EjbService is now processing");
13-
}
10+
@Override
11+
public void doProcessing() {
12+
System.out.println("EjbService is now processing");
13+
}
1414
}
Collapse file

‎business-delegate/src/main/java/com/iluwatar/business/delegate/JmsService.java‎

Copy file name to clipboardExpand all lines: business-delegate/src/main/java/com/iluwatar/business/delegate/JmsService.java
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*/
88
public class JmsService implements BusinessService {
99

10-
@Override
11-
public void doProcessing() {
12-
System.out.println("JmsService is now processing");
13-
}
10+
@Override
11+
public void doProcessing() {
12+
System.out.println("JmsService is now processing");
13+
}
1414
}
Collapse file

‎business-delegate/src/main/java/com/iluwatar/business/delegate/ServiceType.java‎

Copy file name to clipboardExpand all lines: business-delegate/src/main/java/com/iluwatar/business/delegate/ServiceType.java
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
*
77
*/
88
public enum ServiceType {
9-
10-
EJB, JMS;
9+
10+
EJB, JMS;
1111
}
Collapse file

‎business-delegate/src/test/java/com/iluwatar/business/delegate/AppTest.java‎

Copy file name to clipboardExpand all lines: business-delegate/src/test/java/com/iluwatar/business/delegate/AppTest.java
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
*
1111
*/
1212
public class AppTest {
13-
14-
@Test
15-
public void test() {
16-
String[] args = {};
17-
App.main(args);
18-
}
13+
14+
@Test
15+
public void test() {
16+
String[] args = {};
17+
App.main(args);
18+
}
1919
}
Collapse file

‎callback/src/main/java/com/iluwatar/callback/App.java‎

Copy file name to clipboardExpand all lines: callback/src/main/java/com/iluwatar/callback/App.java
+13-12Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22

33
/**
44
*
5-
* Callback pattern is more native for functional languages where functions are treated as first-class citizens.
6-
* Prior to Java 8 callbacks can be simulated using simple (alike command) interfaces.
5+
* Callback pattern is more native for functional languages where functions are treated as
6+
* first-class citizens. Prior to Java 8 callbacks can be simulated using simple (alike command)
7+
* interfaces.
78
*
89
*/
910
public class App {
1011

11-
public static void main(String[] args) {
12-
Task task = new SimpleTask();
13-
Callback callback = new Callback() {
14-
@Override
15-
public void call() {
16-
System.out.println("I'm done now.");
17-
}
18-
};
19-
task.executeWith(callback);
20-
}
12+
public static void main(String[] args) {
13+
Task task = new SimpleTask();
14+
Callback callback = new Callback() {
15+
@Override
16+
public void call() {
17+
System.out.println("I'm done now.");
18+
}
19+
};
20+
task.executeWith(callback);
21+
}
2122
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.