From d81b7beb059c533d11167e103b6bd64ce995c5f2 Mon Sep 17 00:00:00 2001 From: fujiayang Date: Wed, 26 Jan 2022 11:30:05 +0800 Subject: [PATCH] =?UTF-8?q?spring=E5=A2=9E=E5=BC=BA=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=E8=80=85=E6=A8=A1=E5=BC=8F-=E6=94=B9=E9=80=A0=E5=90=8E-jdk17?= =?UTF-8?q?=20Pattern=20Matching?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/misc.xml | 2 +- pom.xml | 4 ++-- .../factorymethod/AbstractVideoFactory.java | 3 --- .../visitor/spring/DrawServiceTest.java | 21 +++++++++++++++++++ 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 3ccb27b..160f392 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -11,7 +11,7 @@ - + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 3ce10da..a2c76a8 100644 --- a/pom.xml +++ b/pom.xml @@ -12,8 +12,8 @@ UTF-8 - 1.8 - 1.8 + 17 + 17 5.1.0.RELEASE diff --git a/src/main/java/top/fjy8018/designpattern/pattern/creational/factorymethod/AbstractVideoFactory.java b/src/main/java/top/fjy8018/designpattern/pattern/creational/factorymethod/AbstractVideoFactory.java index 984ba08..bcb7b64 100644 --- a/src/main/java/top/fjy8018/designpattern/pattern/creational/factorymethod/AbstractVideoFactory.java +++ b/src/main/java/top/fjy8018/designpattern/pattern/creational/factorymethod/AbstractVideoFactory.java @@ -1,8 +1,5 @@ package top.fjy8018.designpattern.pattern.creational.factorymethod; -import sun.misc.Launcher; - -import java.util.Collection; /** * 定义一个创建产品对象的工厂接口,将实际创建工作推迟到子类当中 diff --git a/src/test/java/top/fjy8018/designpattern/pattern/behavior/visitor/spring/DrawServiceTest.java b/src/test/java/top/fjy8018/designpattern/pattern/behavior/visitor/spring/DrawServiceTest.java index eb1fff0..2dc6f0a 100644 --- a/src/test/java/top/fjy8018/designpattern/pattern/behavior/visitor/spring/DrawServiceTest.java +++ b/src/test/java/top/fjy8018/designpattern/pattern/behavior/visitor/spring/DrawServiceTest.java @@ -29,6 +29,14 @@ class DrawServiceTest { draw(new Factory()); } + /** + * 输出:draw factory + */ + @Test + public void draw17() { + draw17(new Factory()); + } + @Test public void draw2() { Visitor drawVisitor = new DrawVisitor(); @@ -52,4 +60,17 @@ class DrawServiceTest { } } + private void draw17(Node node) { + DrawService drawService = new DrawService(); + if (node instanceof Building building) { + drawService.draw(building); + } else if (node instanceof Factory factory) { + drawService.draw(factory); + } else if (node instanceof School school) { + drawService.draw(school); + } else { + drawService.draw(node); + } + } + } \ No newline at end of file