File tree Expand file tree Collapse file tree 9 files changed +96
-3
lines changed Expand file tree Collapse file tree 9 files changed +96
-3
lines changed Original file line number Diff line number Diff line change 58
58
the License.
59
59
```
60
60
61
- [ runoob.com ] :< https://www.tutorialspoint.com/design_pattern/index.htm >
62
- [ ] :< http://www.runoob.com/design-pattern/design-pattern-tutorial.html >
61
+ [ tutorialspoint ] :< https://www.tutorialspoint.com/design_pattern/index.htm >
62
+ [ runoob.com ] :< http://www.runoob.com/design-pattern/design-pattern-tutorial.html >
63
63
[ English ] :< https://github.com/Catherine22/DesignPattern/blob/master/README.md >
64
64
[ LazyInitializingSingleton ] :< https://github.com/Catherine22/DesignPattern/blob/master/src/com/catherine/singleton/LazyInitializingSingleton.java >
65
65
[ SafeLazyInitializingSingleton ] :< https://github.com/Catherine22/DesignPattern/blob/master/src/com/catherine/singleton/SafeLazyInitializingSingleton.java >
Original file line number Diff line number Diff line change 13
13
import com .catherine .builder .OldStyleRobotBuilder ;
14
14
import com .catherine .builder .Robot ;
15
15
import com .catherine .builder .RobotDirector ;
16
+ import com .catherine .business_delegate .BusinessDelegate ;
17
+ import com .catherine .business_delegate .Client ;
18
+ import com .catherine .business_delegate .ServiceType ;
16
19
import com .catherine .chain_of_responsibility .DebugLogger ;
17
20
import com .catherine .chain_of_responsibility .ErrorLogger ;
18
21
import com .catherine .chain_of_responsibility .Logger ;
@@ -107,10 +110,21 @@ public static void main(String[] args) {
107
110
// testStrategy();
108
111
// testTemplate();
109
112
// testVisitor();
110
- testMVC ();
113
+ // testMVC();
114
+ testBusinessDelegate ();
111
115
112
116
}
113
117
118
+ private static void testBusinessDelegate () {
119
+ BusinessDelegate bd = new BusinessDelegate (ServiceType .EJB );
120
+ Client client = new Client (bd );
121
+ client .createTask ();
122
+
123
+ bd = new BusinessDelegate (ServiceType .JMS );
124
+ client = new Client (bd );
125
+ client .createTask ();
126
+ }
127
+
114
128
private static void testMVC () {
115
129
RetrieveCouponFromDB rc = new RetrieveCouponFromDB ();
116
130
rc .downloadCoupons ();
Original file line number Diff line number Diff line change
1
+ package com .catherine .business_delegate ;
2
+
3
+ import com .catherine .business_delegate .ServiceType ;
4
+
5
+ /**
6
+ * 作为入口,用来访问BusinessService
7
+ *
8
+ * @author Catherine
9
+ *
10
+ */
11
+ public class BusinessDelegate {
12
+ private ServiceType type ;
13
+
14
+ public BusinessDelegate (ServiceType type ) {
15
+ this .type = type ;
16
+ }
17
+
18
+ public void createTask () {
19
+ BusinessLookUp blu = new BusinessLookUp ();
20
+ BusinessService service = blu .getBusinessService (type );
21
+ service .bindService ();
22
+ }
23
+ }
Original file line number Diff line number Diff line change
1
+ package com .catherine .business_delegate ;
2
+
3
+ public class BusinessLookUp {
4
+
5
+ public BusinessService getBusinessService (ServiceType type ) {
6
+ if (type == ServiceType .EJB )
7
+ return new EJBService ();
8
+ else
9
+ return new JMSService ();
10
+ }
11
+ }
Original file line number Diff line number Diff line change
1
+ package com .catherine .business_delegate ;
2
+
3
+ public interface BusinessService {
4
+ public void bindService ();
5
+ }
Original file line number Diff line number Diff line change
1
+ package com .catherine .business_delegate ;
2
+
3
+ public class Client {
4
+ BusinessDelegate bd ;
5
+
6
+ public Client (BusinessDelegate bd ) {
7
+ this .bd = bd ;
8
+ }
9
+
10
+ public void createTask () {
11
+ bd .createTask ();
12
+ }
13
+ }
Original file line number Diff line number Diff line change
1
+ package com .catherine .business_delegate ;
2
+
3
+ public class EJBService implements BusinessService {
4
+
5
+ @ Override
6
+ public void bindService () {
7
+ System .out .println ("bind EJBService" );
8
+
9
+ }
10
+
11
+ }
Original file line number Diff line number Diff line change
1
+ package com .catherine .business_delegate ;
2
+
3
+ public class JMSService implements BusinessService {
4
+
5
+ @ Override
6
+ public void bindService () {
7
+ System .out .println ("bind JMSService" );
8
+
9
+ }
10
+
11
+ }
Original file line number Diff line number Diff line change
1
+ package com .catherine .business_delegate ;
2
+
3
+ public enum ServiceType {
4
+ EJB , JMS
5
+ }
You can’t perform that action at this time.
0 commit comments