+ * Copyright (c) 2017 James + *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *
+ * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package me.zbl.strategy; + +/** + * Strategy + */ +public class Application { + + public static void main(String[] args) { + BusinessMan man = new BusinessMan(new TransportationAirplane()); + man.transport(); + + man.changetStrategy(new TransportationTrain()); + man.transport(); + + man.changetStrategy(new TransportationVehicle()); + man.transport(); + } +} diff --git a/strategy/src/main/java/me/zbl/strategy/BusinessMan.java b/strategy/src/main/java/me/zbl/strategy/BusinessMan.java new file mode 100644 index 0000000..bb484a0 --- /dev/null +++ b/strategy/src/main/java/me/zbl/strategy/BusinessMan.java @@ -0,0 +1,44 @@ +/** + * MIT License + *
+ * Copyright (c) 2017 James + *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *
+ * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package me.zbl.strategy; + +/** + * 商人 + */ +public class BusinessMan { + + private TransportationStrategy strategy; + + public BusinessMan(TransportationStrategy strategy) { + this.strategy = strategy; + } + + public void changetStrategy(TransportationStrategy strategy) { + this.strategy = strategy; + } + + public void transport() { + this.strategy.go(); + } +} diff --git a/strategy/src/main/java/me/zbl/strategy/TransportationAirplane.java b/strategy/src/main/java/me/zbl/strategy/TransportationAirplane.java new file mode 100644 index 0000000..3a4ce0b --- /dev/null +++ b/strategy/src/main/java/me/zbl/strategy/TransportationAirplane.java @@ -0,0 +1,40 @@ +/** + * MIT License + *
+ * Copyright (c) 2017 James + *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *
+ * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package me.zbl.strategy; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * 乘飞机 + */ +public class TransportationAirplane implements TransportationStrategy { + + private static final Logger LOGGER = LoggerFactory.getLogger(TransportationAirplane.class); + + @Override + public void go() { + LOGGER.info("乘飞机从北京去广州"); + } +} diff --git a/strategy/src/main/java/me/zbl/strategy/TransportationStrategy.java b/strategy/src/main/java/me/zbl/strategy/TransportationStrategy.java new file mode 100644 index 0000000..96db438 --- /dev/null +++ b/strategy/src/main/java/me/zbl/strategy/TransportationStrategy.java @@ -0,0 +1,33 @@ +/** + * MIT License + *
+ * Copyright (c) 2017 James + *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *
+ * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package me.zbl.strategy; + +/** + * 交通方式策略 + */ +@FunctionalInterface +public interface TransportationStrategy { + + void go(); +} diff --git a/strategy/src/main/java/me/zbl/strategy/TransportationTrain.java b/strategy/src/main/java/me/zbl/strategy/TransportationTrain.java new file mode 100644 index 0000000..b7318f0 --- /dev/null +++ b/strategy/src/main/java/me/zbl/strategy/TransportationTrain.java @@ -0,0 +1,40 @@ +/** + * MIT License + *
+ * Copyright (c) 2017 James + *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *
+ * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package me.zbl.strategy; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * 乘火车 + */ +public class TransportationTrain implements TransportationStrategy { + + private static final Logger LOGGER = LoggerFactory.getLogger(TransportationTrain.class); + + @Override + public void go() { + LOGGER.info("乘高铁从北京去上海"); + } +} diff --git a/strategy/src/main/java/me/zbl/strategy/TransportationVehicle.java b/strategy/src/main/java/me/zbl/strategy/TransportationVehicle.java new file mode 100644 index 0000000..ffbffc4 --- /dev/null +++ b/strategy/src/main/java/me/zbl/strategy/TransportationVehicle.java @@ -0,0 +1,40 @@ +/** + * MIT License + *
+ * Copyright (c) 2017 James + *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *
+ * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package me.zbl.strategy;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 驾车
+ */
+public class TransportationVehicle implements TransportationStrategy {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(TransportationVehicle.class);
+
+ @Override
+ public void go() {
+ LOGGER.info("驾车从北京去天津");
+ }
+}
From 991fd52a01b52fa6c9f32f46d379d2ed637c42e2 Mon Sep 17 00:00:00 2001
From: James <1146556298@qq.com>
Date: Wed, 29 Nov 2017 21:49:03 +0800
Subject: [PATCH 2/8] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20=E6=A8=A1=E6=9D=BF?=
=?UTF-8?q?=E6=96=B9=E6=B3=95=E6=A8=A1=E5=BC=8F=20Module?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 1 +
template-method/pom.xml | 51 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+)
create mode 100644 template-method/pom.xml
diff --git a/pom.xml b/pom.xml
index 771cc5f..539135c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -66,6 +66,7 @@
+ * Copyright (c) 2017 James
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Template method
+ */
+public class Application {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(Application.class);
+
+ public static void main(String[] args) {
+ Student student = new Student(new PositiveLearningMethod());
+ student.learn("上课走神", "同学");
+ LOGGER.info("更换学习方法");
+ student.changeMethod(new NegativeLearinngMethod());
+ student.learn("认证听讲", "老师");
+ }
+}
diff --git a/template-method/src/main/java/LearningMethod.java b/template-method/src/main/java/LearningMethod.java
new file mode 100644
index 0000000..5515542
--- /dev/null
+++ b/template-method/src/main/java/LearningMethod.java
@@ -0,0 +1,68 @@
+/**
+ * MIT License
+ *
+ * Copyright (c) 2017 James
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 学习方法的抽象类
+ */
+public abstract class LearningMethod {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(LearningMethod.class);
+
+ /**
+ * 预习效果
+ *
+ * @return
+ */
+ protected abstract String preLearning();
+
+ /**
+ * 状态
+ *
+ * @param description 学习状态
+ */
+ protected abstract void Learning(String description);
+
+ /**
+ * 请教对象
+ *
+ * @param adviser 请教对象
+ */
+ protected abstract void afterLearning(String adviser);
+
+ /**
+ * 学习过程
+ *
+ * @param description 听课状态
+ * @param adviser 请假对象
+ */
+ public void learn(String description, String adviser) {
+ String preLearningResult = preLearning();
+ LOGGER.info("{}", preLearningResult);
+ Learning(description);
+ afterLearning(adviser);
+ }
+}
diff --git a/template-method/src/main/java/NegativeLearinngMethod.java b/template-method/src/main/java/NegativeLearinngMethod.java
new file mode 100644
index 0000000..a178faf
--- /dev/null
+++ b/template-method/src/main/java/NegativeLearinngMethod.java
@@ -0,0 +1,51 @@
+/**
+ * MIT License
+ *
+ * Copyright (c) 2017 James
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 消极的学习方法
+ */
+public class NegativeLearinngMethod extends LearningMethod {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(NegativeLearinngMethod.class);
+
+ @Override
+ protected String preLearning() {
+ return "几乎没有预习,对上课要学的内容一无所知";
+ }
+
+ @Override
+ protected void Learning(String description) {
+ LOGGER.info("学习状态:{}", description);
+ }
+
+ @Override
+ protected void afterLearning(String adviser) {
+ if (!adviser.equals("")) {
+ LOGGER.info("只有很少的知识点没有听懂,于是找{}提问", adviser);
+ }
+ }
+}
diff --git a/template-method/src/main/java/PositiveLearningMethod.java b/template-method/src/main/java/PositiveLearningMethod.java
new file mode 100644
index 0000000..5fabb15
--- /dev/null
+++ b/template-method/src/main/java/PositiveLearningMethod.java
@@ -0,0 +1,51 @@
+/**
+ * MIT License
+ *
+ * Copyright (c) 2017 James
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 积极的学习方法
+ */
+public class PositiveLearningMethod extends LearningMethod {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(PositiveLearningMethod.class);
+
+ @Override
+ protected String preLearning() {
+ return "预习到位,为听课打下很好的基础";
+ }
+
+ @Override
+ protected void Learning(String description) {
+ LOGGER.info("学习状态:{}", description);
+ }
+
+ @Override
+ protected void afterLearning(String adviser) {
+ if (!adviser.equals("")) {
+ LOGGER.info("只有很少的知识点没有听懂,于是找{}提问", adviser);
+ }
+ }
+}
diff --git a/template-method/src/main/java/Student.java b/template-method/src/main/java/Student.java
new file mode 100644
index 0000000..cbe230f
--- /dev/null
+++ b/template-method/src/main/java/Student.java
@@ -0,0 +1,54 @@
+/**
+ * MIT License
+ *
+ * Copyright (c) 2017 James
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+/**
+ * 学生
+ */
+public class Student {
+
+ private LearningMethod method;
+
+ public Student(LearningMethod method) {
+ this.method = method;
+ }
+
+ /**
+ * 学习
+ *
+ * @param description 状态
+ * @param adviser 请教对象
+ */
+ public void learn(String description, String adviser) {
+ method.learn(description, adviser);
+ }
+
+ /**
+ * 更换学习方法
+ *
+ * @param method
+ */
+ public void changeMethod(LearningMethod method) {
+ this.method = method;
+ }
+}
From 1177e07dcfca14724b94d7821eb1a63ecd4587fb Mon Sep 17 00:00:00 2001
From: James <1146556298@qq.com>
Date: Wed, 29 Nov 2017 22:31:32 +0800
Subject: [PATCH 4/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20=E6=A8=A1=E6=9D=BF?=
=?UTF-8?q?=E6=96=B9=E6=B3=95=20module=20=E5=90=8D=E7=A7=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 539135c..1404ac6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -66,7 +66,7 @@
+ * Copyright (c) 2017 James
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package me.zbl.visitor;
+
+/**
+ * 老板
+ */
+public class Boss extends Unit {
+
+ public Boss(Unit... children) {
+ super(children);
+ }
+
+ @Override
+ public void beVisited(UnitVisitor visitor) {
+ visitor.visitBoss(this);
+ super.beVisited(visitor);
+ }
+
+ @Override
+ public String toString() {
+ return "老板";
+ }
+}
diff --git a/visitor/src/main/java/me/zbl/visitor/BossVisitor.java b/visitor/src/main/java/me/zbl/visitor/BossVisitor.java
new file mode 100644
index 0000000..387d913
--- /dev/null
+++ b/visitor/src/main/java/me/zbl/visitor/BossVisitor.java
@@ -0,0 +1,50 @@
+/**
+ * MIT License
+ *
+ * Copyright (c) 2017 James
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package me.zbl.visitor;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 老板的访问者
+ */
+public class BossVisitor implements UnitVisitor {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(BossVisitor.class);
+
+ @Override
+ public void visitEngineer(Engineer engineer) {
+
+ }
+
+ @Override
+ public void visitBoss(Boss boss) {
+ LOGGER.info("你好,{}", boss);
+ }
+
+ @Override
+ public void visitManager(Manager manager) {
+
+ }
+}
diff --git a/visitor/src/main/java/me/zbl/visitor/Engineer.java b/visitor/src/main/java/me/zbl/visitor/Engineer.java
new file mode 100644
index 0000000..f90b317
--- /dev/null
+++ b/visitor/src/main/java/me/zbl/visitor/Engineer.java
@@ -0,0 +1,45 @@
+/**
+ * MIT License
+ *
+ * Copyright (c) 2017 James
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package me.zbl.visitor;
+
+/**
+ * 工程师
+ */
+public class Engineer extends Unit {
+
+ public Engineer(Unit... children) {
+ super(children);
+ }
+
+ @Override
+ public void beVisited(UnitVisitor visitor) {
+ visitor.visitEngineer(this);
+ super.beVisited(visitor);
+ }
+
+ @Override
+ public String toString() {
+ return "工程师";
+ }
+}
diff --git a/visitor/src/main/java/me/zbl/visitor/EngineerVisitor.java b/visitor/src/main/java/me/zbl/visitor/EngineerVisitor.java
new file mode 100644
index 0000000..621acb2
--- /dev/null
+++ b/visitor/src/main/java/me/zbl/visitor/EngineerVisitor.java
@@ -0,0 +1,50 @@
+/**
+ * MIT License
+ *
+ * Copyright (c) 2017 James
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package me.zbl.visitor;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 工程师的访问者
+ */
+public class EngineerVisitor implements UnitVisitor {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(EngineerVisitor.class);
+
+ @Override
+ public void visitEngineer(Engineer engineer) {
+ LOGGER.info("你好,{}", engineer);
+ }
+
+ @Override
+ public void visitBoss(Boss boss) {
+
+ }
+
+ @Override
+ public void visitManager(Manager manager) {
+
+ }
+}
diff --git a/visitor/src/main/java/me/zbl/visitor/Manager.java b/visitor/src/main/java/me/zbl/visitor/Manager.java
new file mode 100644
index 0000000..cd9727a
--- /dev/null
+++ b/visitor/src/main/java/me/zbl/visitor/Manager.java
@@ -0,0 +1,45 @@
+/**
+ * MIT License
+ *
+ * Copyright (c) 2017 James
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package me.zbl.visitor;
+
+/**
+ * 经理
+ */
+public class Manager extends Unit {
+
+ public Manager(Unit... children) {
+ super(children);
+ }
+
+ @Override
+ public void beVisited(UnitVisitor visitor) {
+ visitor.visitManager(this);
+ super.beVisited(visitor);
+ }
+
+ @Override
+ public String toString() {
+ return "经理";
+ }
+}
diff --git a/visitor/src/main/java/me/zbl/visitor/ManagerVisitor.java b/visitor/src/main/java/me/zbl/visitor/ManagerVisitor.java
new file mode 100644
index 0000000..1286372
--- /dev/null
+++ b/visitor/src/main/java/me/zbl/visitor/ManagerVisitor.java
@@ -0,0 +1,50 @@
+/**
+ * MIT License
+ *
+ * Copyright (c) 2017 James
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package me.zbl.visitor;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 经理的访问者
+ */
+public class ManagerVisitor implements UnitVisitor {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ManagerVisitor.class);
+
+ @Override
+ public void visitEngineer(Engineer engineer) {
+
+ }
+
+ @Override
+ public void visitBoss(Boss boss) {
+
+ }
+
+ @Override
+ public void visitManager(Manager manager) {
+ LOGGER.info("你好,{}", manager);
+ }
+}
diff --git a/visitor/src/main/java/me/zbl/visitor/Unit.java b/visitor/src/main/java/me/zbl/visitor/Unit.java
new file mode 100644
index 0000000..d80312f
--- /dev/null
+++ b/visitor/src/main/java/me/zbl/visitor/Unit.java
@@ -0,0 +1,45 @@
+/**
+ * MIT License
+ *
+ * Copyright (c) 2017 James
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package me.zbl.visitor;
+
+/**
+ * 可访问的单元
+ */
+public abstract class Unit {
+
+ private Unit[] children;
+
+ public Unit(Unit... children) {
+ this.children = children;
+ }
+
+ /**
+ * 接受访问
+ */
+ public void beVisited(UnitVisitor visitor) {
+ for (Unit childUnit : children) {
+ childUnit.beVisited(visitor);
+ }
+ }
+}
diff --git a/visitor/src/main/java/me/zbl/visitor/UnitVisitor.java b/visitor/src/main/java/me/zbl/visitor/UnitVisitor.java
new file mode 100644
index 0000000..932b419
--- /dev/null
+++ b/visitor/src/main/java/me/zbl/visitor/UnitVisitor.java
@@ -0,0 +1,36 @@
+/**
+ * MIT License
+ *
+ * Copyright (c) 2017 James
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package me.zbl.visitor;
+
+/**
+ * 访问者接口
+ */
+public interface UnitVisitor {
+
+ void visitEngineer(Engineer engineer);
+
+ void visitBoss(Boss boss);
+
+ void visitManager(Manager manager);
+}