File tree Expand file tree Collapse file tree 12 files changed +748
-0
lines changed
design-patterns/src/main/java/pers/huangyuhui/adapter_pattern Expand file tree Collapse file tree 12 files changed +748
-0
lines changed Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change
1
+ package pers .huangyuhui .adapter_pattern .adapter1 ;
2
+
3
+ /**
4
+ * @project: design-patterns
5
+ * @description: 充当Adaptee角色
6
+ * @author: 黄宇辉
7
+ * @date: 9/3/2019-4:12 PM
8
+ * @version: 1.0
9
+ * @website: https://yubuntu0109.github.io/
10
+ */
11
+ public class Banner {
12
+ private String string ;
13
+
14
+ public Banner (String string ) {
15
+ this .string = string ;
16
+ }
17
+
18
+ public void showWithParen () {
19
+ System .out .println ("(" + string + ")" );
20
+ }
21
+
22
+ public void showWithAster () {
23
+ System .out .println ("*" + string + "*" );
24
+ }
25
+
26
+ }
Original file line number Diff line number Diff line change
1
+ package pers .huangyuhui .adapter_pattern .adapter1 ;
2
+
3
+ /**
4
+ * @project: design-patterns
5
+ * @description: 充当Client角色
6
+ * @author: 黄宇辉
7
+ * @date: 9/3/2019-4:17 PM
8
+ * @version: 1.0
9
+ * @website: https://yubuntu0109.github.io/
10
+ */
11
+ public class Main {
12
+ public static void main (String [] args ) {
13
+ Print print = new PrintBanner ("Hello" );
14
+ print .printWeak ();
15
+ print .printStrong ();
16
+ }
17
+ }
Original file line number Diff line number Diff line change
1
+ package pers .huangyuhui .adapter_pattern .adapter1 ;
2
+
3
+ /**
4
+ * @project: design-patterns
5
+ * @description: 充当Target角色
6
+ * @author: 黄宇辉
7
+ * @date: 9/3/2019-4:15 PM
8
+ * @version: 1.0
9
+ * @website: https://yubuntu0109.github.io/
10
+ */
11
+ public interface Print {
12
+ void printWeak ();
13
+
14
+ void printStrong ();
15
+ }
Original file line number Diff line number Diff line change
1
+ package pers .huangyuhui .adapter_pattern .adapter1 ;
2
+
3
+ /**
4
+ * @project: design-patterns
5
+ * @description: 充当Adapter角色
6
+ * @author: 黄宇辉
7
+ * @date: 9/3/2019-4:16 PM
8
+ * @version: 1.0
9
+ * @website: https://yubuntu0109.github.io/
10
+ */
11
+ public class PrintBanner extends Banner implements Print {
12
+
13
+ public PrintBanner (String string ) {
14
+ super (string );
15
+ }
16
+
17
+ @ Override
18
+ public void printWeak () {
19
+ super .showWithParen ();
20
+ }
21
+
22
+ @ Override
23
+ public void printStrong () {
24
+ super .showWithAster ();
25
+ }
26
+ }
Original file line number Diff line number Diff line change
1
+ package pers .huangyuhui .adapter_pattern .adapter2 ;
2
+
3
+ /**
4
+ * @project: design-patterns
5
+ * @description: 充当Adaptee角色
6
+ * @author: 黄宇辉
7
+ * @date: 9/3/2019-4:23 PM
8
+ * @version: 1.0
9
+ * @website: https://yubuntu0109.github.io/
10
+ */
11
+ public class Banner {
12
+ private String string ;
13
+
14
+ public Banner (String string ) {
15
+ this .string = string ;
16
+ }
17
+
18
+ public void showWithParen () {
19
+ System .out .println ("(" + string + ")" );
20
+ }
21
+
22
+ public void showWithAster () {
23
+ System .out .println ("*" + string + "*" );
24
+ }
25
+ }
Original file line number Diff line number Diff line change
1
+ package pers .huangyuhui .adapter_pattern .adapter2 ;
2
+
3
+ /**
4
+ * @project: design-patterns
5
+ * @description: 充当Client角色
6
+ * @author: 黄宇辉
7
+ * @date: 9/3/2019-4:26 PM
8
+ * @version: 1.0
9
+ * @website: https://yubuntu0109.github.io/
10
+ */
11
+ public class Main {
12
+
13
+ public static void main (String [] args ) {
14
+ Print print = new PrintBanner ("Adapter Pattern" );
15
+ print .printWeak ();
16
+ print .pintStrong ();
17
+
18
+ }
19
+ }
Original file line number Diff line number Diff line change
1
+ package pers .huangyuhui .adapter_pattern .adapter2 ;
2
+
3
+ /**
4
+ * @project: design-patterns
5
+ * @description: 充当Target角色
6
+ * @author: 黄宇辉
7
+ * @date: 9/3/2019-4:21 PM
8
+ * @version: 1.0
9
+ * @website: https://yubuntu0109.github.io/
10
+ */
11
+ public abstract class Print {
12
+ public abstract void printWeak ();
13
+
14
+ public abstract void pintStrong ();
15
+ }
Original file line number Diff line number Diff line change
1
+ package pers .huangyuhui .adapter_pattern .adapter2 ;
2
+
3
+ /**
4
+ * @project: design-patterns
5
+ * @description: 充当Adapter角色
6
+ * @author: 黄宇辉
7
+ * @date: 9/3/2019-4:22 PM
8
+ * @version: 1.0
9
+ * @website: https://yubuntu0109.github.io/
10
+ */
11
+ public class PrintBanner extends Print {
12
+
13
+ private Banner banner ;
14
+
15
+ public PrintBanner (String string ) {
16
+ this .banner = new Banner (string );
17
+ }
18
+
19
+ @ Override
20
+ public void printWeak () {
21
+ banner .showWithParen ();
22
+ }
23
+
24
+ @ Override
25
+ public void pintStrong () {
26
+ banner .showWithAster ();
27
+ }
28
+ }
Original file line number Diff line number Diff line change
1
+ package pers .huangyuhui .adapter_pattern .adapter3 ;
2
+
3
+ import javax .swing .*;
4
+ import java .awt .event .MouseAdapter ;
5
+ import java .awt .event .MouseEvent ;
6
+ import java .awt .event .WindowAdapter ;
7
+ import java .awt .event .WindowEvent ;
8
+
9
+ /**
10
+ * @project: design-patterns
11
+ * @description: 测试
12
+ * @author: 黄宇辉
13
+ * @date: 9/3/2019-4:47 PM
14
+ * @version: 1.0
15
+ * @website: https://yubuntu0109.github.io/
16
+ */
17
+ public class MyController {
18
+ public static void main (String [] args ) {
19
+ MyEventService myEventService = new MyEventService ();
20
+ JFrame j = new JFrame ("title" );
21
+ j .setSize (500 , 300 );
22
+ j .setVisible (true );
23
+ j .setLocationRelativeTo (null );
24
+ j .setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
25
+
26
+ //绑定事件
27
+ j .addWindowListener (new WindowAdapter () {
28
+ @ Override
29
+ public void windowOpened (WindowEvent e ) {
30
+ myEventService .windowOpened (e );
31
+ }
32
+
33
+ @ Override
34
+ public void windowClosing (WindowEvent e ) {
35
+ myEventService .windowClosing (e );
36
+ }
37
+ });
38
+ j .addMouseListener (new MouseAdapter () {
39
+ @ Override
40
+ public void mouseClicked (MouseEvent e ) {
41
+ myEventService .mouseClicked (e );
42
+ }
43
+ });
44
+
45
+ }
46
+ }
You can’t perform that action at this time.
0 commit comments