spring增强访问者模式-改造后-jdk17 Pattern Matching

This commit is contained in:
fujiayang
2022-01-26 11:30:05 +08:00
parent 3f52da2575
commit d81b7beb05
4 changed files with 24 additions and 6 deletions

View File

@@ -1,8 +1,5 @@
package top.fjy8018.designpattern.pattern.creational.factorymethod;
import sun.misc.Launcher;
import java.util.Collection;
/**
* 定义一个创建产品对象的工厂接口,将实际创建工作推迟到子类当中

View File

@@ -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);
}
}
}