|
| 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 org.slf4j.Logger; |
| 27 | +import org.slf4j.LoggerFactory; |
| 28 | + |
| 29 | +/** |
| 30 | + * 课堂参与者抽象类 |
| 31 | + */ |
| 32 | +public abstract class CourseParticipator { |
| 33 | + |
| 34 | + private static final Logger LOGGER = LoggerFactory.getLogger(CourseParticipator.class); |
| 35 | + |
| 36 | + public void prepareCourse() { |
| 37 | + LOGGER.info("{}准备上课", name()); |
| 38 | + } |
| 39 | + |
| 40 | + public void proceedCourse() { |
| 41 | + LOGGER.info("{}正在上课", name()); |
| 42 | + } |
| 43 | + |
| 44 | + public void stopCourse() { |
| 45 | + LOGGER.info("{}下课", name()); |
| 46 | + } |
| 47 | + |
| 48 | + public void goToSchool() { |
| 49 | + LOGGER.info("{}赶往学校", name()); |
| 50 | + } |
| 51 | + |
| 52 | + public void goHome() { |
| 53 | + LOGGER.info("{}回家", name()); |
| 54 | + } |
| 55 | + |
| 56 | + public abstract String name(); |
| 57 | + |
| 58 | + public void action(Event... events) { |
| 59 | + for (Event e : events) { |
| 60 | + action(e); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + private void action(Event e) { |
| 65 | + switch (e) { |
| 66 | + case EVENT_PREPARE: { |
| 67 | + prepareCourse(); |
| 68 | + break; |
| 69 | + } |
| 70 | + case EVENT_PROCEED: { |
| 71 | + proceedCourse(); |
| 72 | + break; |
| 73 | + } |
| 74 | + case EVENT_STOP: { |
| 75 | + stopCourse(); |
| 76 | + break; |
| 77 | + } |
| 78 | + case EVENT_GO_HOME: { |
| 79 | + goHome(); |
| 80 | + break; |
| 81 | + } |
| 82 | + case EVENT_GOTO_SCHOOL: { |
| 83 | + goToSchool(); |
| 84 | + break; |
| 85 | + } |
| 86 | + default: { |
| 87 | + LOGGER.info("未知操作"); |
| 88 | + break; |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + static enum Event { |
| 94 | + EVENT_GOTO_SCHOOL, EVENT_PREPARE, EVENT_PROCEED, EVENT_STOP, EVENT_GO_HOME; |
| 95 | + } |
| 96 | +} |
0 commit comments