Skip to content

Commit ddc6dda

Browse files
committed
完成 外观模式
1 parent 7bb1b76 commit ddc6dda

File tree

4 files changed

+137
-1
lines changed

4 files changed

+137
-1
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* MIT License
3+
* <p>
4+
* Copyright (c) 2017 James
5+
* <p>
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
* <p>
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
* <p>
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package me.zbl.facade;
25+
26+
/**
27+
* Facade
28+
*/
29+
public class Application {
30+
31+
public static void main(String[] args) {
32+
CourseFacade participator = new CourseFacade();
33+
participator.prepare();
34+
participator.proceed();
35+
participator.stop();
36+
}
37+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* MIT License
3+
* <p>
4+
* Copyright (c) 2017 James
5+
* <p>
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
* <p>
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
* <p>
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package me.zbl.facade;
25+
26+
import java.util.ArrayList;
27+
import java.util.List;
28+
29+
/**
30+
* 课程外观
31+
*/
32+
public class CourseFacade {
33+
34+
private final List<CourseParticipator> participators;
35+
36+
public CourseFacade() {
37+
participators = new ArrayList<>();
38+
participators.add(new CourseTeacher());
39+
participators.add(new CourseStudent());
40+
}
41+
42+
public void prepare() {
43+
for (CourseParticipator participator :
44+
participators) {
45+
participator.action(CourseParticipator.Event.EVENT_GOTO_SCHOOL);
46+
participator.action(CourseParticipator.Event.EVENT_PREPARE);
47+
}
48+
}
49+
50+
public void proceed() {
51+
for (CourseParticipator participator :
52+
participators) {
53+
participator.action(CourseParticipator.Event.EVENT_PROCEED);
54+
}
55+
}
56+
57+
public void stop() {
58+
for (CourseParticipator participator :
59+
participators) {
60+
participator.action(CourseParticipator.Event.EVENT_STOP);
61+
participator.action(CourseParticipator.Event.EVENT_GO_HOME);
62+
}
63+
}
64+
}

facade/src/main/java/me/zbl/facade/CourseStudent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
package me.zbl.facade;
2525

2626
/**
27-
* 教师
27+
* 学生
2828
*/
2929
public class CourseStudent extends CourseParticipator {
3030

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* MIT License
3+
* <p>
4+
* Copyright (c) 2017 James
5+
* <p>
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
* <p>
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
* <p>
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package me.zbl.facade;
25+
26+
/**
27+
* 教师
28+
*/
29+
public class CourseTeacher extends CourseParticipator {
30+
31+
@Override
32+
public String name() {
33+
return "老师";
34+
}
35+
}

0 commit comments

Comments
 (0)