File tree 9 files changed +103
-0
lines changed
9 files changed +103
-0
lines changed Original file line number Diff line number Diff line change
1
+ # ## IntelliJ IDEA ###
2
+ out /
3
+ ! ** /src /main /** /out /
4
+ ! ** /src /test /** /out /
5
+
6
+ # ## Eclipse ###
7
+ .apt_generated
8
+ .classpath
9
+ .factorypath
10
+ .project
11
+ .settings
12
+ .springBeans
13
+ .sts4-cache
14
+ bin /
15
+ ! ** /src /main /** /bin /
16
+ ! ** /src /test /** /bin /
17
+
18
+ # ## NetBeans ###
19
+ /nbproject /private /
20
+ /nbbuild /
21
+ /dist /
22
+ /nbdist /
23
+ /.nb-gradle /
24
+
25
+ # ## VS Code ###
26
+ .vscode /
27
+
28
+ # ## Mac OS ###
29
+ .DS_Store
30
+
31
+ .idea
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <module type =" JAVA_MODULE" version =" 4" >
3
+ <component name =" NewModuleRootManager" inherit-compiler-output =" true" >
4
+ <exclude-output />
5
+ <content url =" file://$MODULE_DIR$" >
6
+ <sourceFolder url =" file://$MODULE_DIR$/src" isTestSource =" false" />
7
+ </content >
8
+ <orderEntry type =" inheritedJdk" />
9
+ <orderEntry type =" sourceFolder" forTests =" false" />
10
+ </component >
11
+ </module >
Original file line number Diff line number Diff line change
1
+ package creational .factory ;
2
+
3
+ public interface Channel {
4
+ void showConnection ();
5
+ }
Original file line number Diff line number Diff line change
1
+ package creational .factory ;
2
+
3
+ public class ChannelFactory {
4
+ public static Channel createTCPChannel () {
5
+ return new TCPChannel ();
6
+ }
7
+
8
+ public static Channel createUDPChannel () {
9
+ return new UDPChannel ();
10
+ }
11
+ }
Original file line number Diff line number Diff line change
1
+ package creational .factory ;
2
+
3
+ public class ClientTCP {
4
+ public ClientTCP () {
5
+ Channel channel = ChannelFactory .createTCPChannel ();
6
+ }
7
+ }
Original file line number Diff line number Diff line change
1
+ package creational .factory ;
2
+
3
+ public class ClientUDP {
4
+ public ClientUDP () {
5
+ Channel channel = ChannelFactory .createUDPChannel ();
6
+ }
7
+ }
Original file line number Diff line number Diff line change
1
+ package creational .factory ;
2
+
3
+ public class Factory {
4
+ public static void main (String [] args ) {
5
+ ClientTCP clientTCP = new ClientTCP ();
6
+ ClientUDP clientUDP = new ClientUDP ();
7
+ }
8
+ }
Original file line number Diff line number Diff line change
1
+ package creational .factory ;
2
+
3
+ public class TCPChannel implements Channel {
4
+ public TCPChannel () {
5
+ this .showConnection ();
6
+ }
7
+
8
+ @ Override
9
+ public void showConnection () {
10
+ System .out .println ("Connected TCP" );
11
+ }
12
+ }
Original file line number Diff line number Diff line change
1
+ package creational .factory ;
2
+
3
+ public class UDPChannel implements Channel {
4
+ public UDPChannel () {
5
+ this .showConnection ();
6
+ }
7
+ @ Override
8
+ public void showConnection () {
9
+ System .out .println ("Connected UDP" );
10
+ }
11
+ }
You can’t perform that action at this time.
0 commit comments