Ai
5 Star 36 Fork 25

随心/ProjectStudy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Main.java 811 Bytes
一键复制 编辑 原始数据 按行查看 历史
随心 提交于 2023-02-04 23:06 +08:00 . 设计模式-访问者模式
package com.design.visitor;
/**
* 访问者模式,一个购买组装电脑各种零件,对个人及公司访问者不同优惠的例子
*
* @author wliduo[i@dolyw.com]
* @date 2023/2/3 17:33
*/
public class Main {
public static void main(String[] args) {
// 整个结构对象,也同时充当节点的作用
ComputerStructure computerStructure = new ComputerStructure();
// 个人购买
PersonelVisitorImpl personelVisitor = new PersonelVisitorImpl();
computerStructure.accept(personelVisitor);
System.out.println(personelVisitor.getTotalPrice());
// 公司购买
CorpVisitorImpl corpVisitor = new CorpVisitorImpl();
computerStructure.accept(corpVisitor);
System.out.println(corpVisitor.getTotalPrice());
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/dolyw/ProjectStudy.git
git@gitee.com:dolyw/ProjectStudy.git
dolyw
ProjectStudy
ProjectStudy
master

搜索帮助