当前位置: 首页 > news >正文

成都营销型网站图片制作视频软件

成都营销型网站,图片制作视频软件,企业网站推广计划,宁波网络营销咨询公司上一章链接#xff1a; 《HeadFirst设计模式(第二版)》第九章代码——迭代器模式_轩下小酌的博客-CSDN博客 前面说到#xff0c;当一个菜单里面出现了子菜单的时候#xff0c;前面的迭代器模式得换成组合模式。 组合模式#xff1a; 允许将对象组合成树形结构来表现部分-整…上一章链接 《HeadFirst设计模式(第二版)》第九章代码——迭代器模式_轩下小酌的博客-CSDN博客 前面说到当一个菜单里面出现了子菜单的时候前面的迭代器模式得换成组合模式。 组合模式 允许将对象组合成树形结构来表现部分-整体层次结构。组合让用户可以统一处理个别对象和对象组合。 代码文件结构 MenuComponent package Chapter9_CompositePattern;/*** Author 竹心* Date 2023/8/18**/public abstract class MenuComponent {public void add(MenuComponent menuComponent) {throw new UnsupportedOperationException();}public void remove(MenuComponent menuComponent) {throw new UnsupportedOperationException();}public MenuComponent getChild(int i) {throw new UnsupportedOperationException();}public String getName() {throw new UnsupportedOperationException();}public String getDescription() {throw new UnsupportedOperationException();}public double getPrice() {throw new UnsupportedOperationException();}public boolean isVegetarian() {throw new UnsupportedOperationException();}public void print() {throw new UnsupportedOperationException();} }MenuItem package Chapter9_CompositePattern;/*** Author 竹心* Date 2023/8/18**/public class MenuItem extends MenuComponent{String name;String description;boolean vegetarian;double price;public MenuItem(String name,String description,boolean vegetarian,double price){this.name name;this.description description;this.vegetarian vegetarian;this.price price;}public String getName() {return name;}public String getDescription() {return description;}public double getPrice() {return price;}public boolean isVegetarian() {return vegetarian;}public void print() {System.out.print( getName());if (isVegetarian()) {System.out.print((v));}System.out.println(, getPrice());System.out.println( -- getDescription());} }Menu package Chapter9_CompositePattern;import java.util.ArrayList; import java.util.Iterator;/*** Author 竹心* Date 2023/8/18**/public class Menu extends MenuComponent{//菜单组合ArrayListMenuComponent menuComponents new ArrayListMenuComponent();String name;String description;public Menu(String name, String description) {this.name name;this.description description;}public void add(MenuComponent menuComponent) {menuComponents.add(menuComponent);}public void remove(MenuComponent menuComponent) {menuComponents.remove(menuComponent);}public MenuComponent getChild(int i) {return (MenuComponent)menuComponents.get(i);}public String getName() {return name;}public String getDescription() {return description;}public void print() {System.out.print(\n getName());System.out.println(, getDescription());System.out.println(---------------------);//这里递归打印IteratorMenuComponent iterator menuComponents.iterator();while (iterator.hasNext()) {MenuComponent menuComponent (MenuComponent)iterator.next();menuComponent.print();}} }Waitress  package Chapter9_CompositePattern;/*** Author 竹心* Date 2023/8/18**/public class Waitress {MenuComponent allMenus;//菜单根节点public Waitress(MenuComponent allMenus) {this.allMenus allMenus;}public void printMenu() {allMenus.print();} }MenuTestDrive package Chapter9_CompositePattern;/*** Author 竹心* Date 2023/8/18**/public class MenuTestDrive {public static void main(String args[]) {MenuComponent pancakeHouseMenu new Menu(PANCAKE HOUSE MENU, Breakfast);MenuComponent dinerMenu new Menu(DINER MENU, Lunch);MenuComponent cafeMenu new Menu(CAFE MENU, Dinner);MenuComponent dessertMenu new Menu(DESSERT MENU, Dessert of course!);MenuComponent coffeeMenu new Menu(COFFEE MENU, Stuff to go with your afternoon coffee);MenuComponent allMenus new Menu(ALL MENUS, All menus combined);allMenus.add(pancakeHouseMenu);allMenus.add(dinerMenu);allMenus.add(cafeMenu);pancakeHouseMenu.add(new MenuItem(KBs Pancake Breakfast,Pancakes with scrambled eggs and toast,true,2.99));dinerMenu.add(new MenuItem(Vegetarian BLT,(Fakin) Bacon with lettuce tomato on whole wheat,true,2.99));dinerMenu.add(dessertMenu);dessertMenu.add(new MenuItem(Apple Pie,Apple pie with a flakey crust, topped with vanilla icecream,true,1.59));cafeMenu.add(coffeeMenu);coffeeMenu.add(new MenuItem(Coffee Cake,Crumbly cake topped with cinnamon and walnuts,true,1.59));Waitress waitress new Waitress(allMenus);//这示例代码怎么这么多。。。waitress.printMenu();} }
http://www.dnsts.com.cn/news/173557.html

相关文章:

  • ps做网站尺寸昆山市有没有做网站设计的
  • 吴中区建设局网站网站背景动图怎么做
  • 跨境电商自己做网站引流网站开发后端怎么开发
  • 360网站怎么做ppt营销案例100例小故事及感悟
  • 手机应用下载网站源码卧龙区微网站建设
  • 申请网站建设费用的请示凡科轻站小程序制作平台
  • 个人网站备案需要什么小游戏大全网页版
  • wordpress主题响应式wordpress 百度seo插件
  • 新郑建设局网站中国网站虚拟主机 排名
  • 新闻资讯网站模板网站后台怎么给图片做水印
  • 网站有哪些推荐找别人网站开发没给我源代码
  • 安徽 网站建设中山市网站开发公司
  • 益阳市建设网站太原百度seo优化推广
  • 手机版的学习网站wordpress 标题字号
  • 电子商务网站建设核心网络公司网站制作岗位职责
  • 上海网站建设空间微营销手机
  • 嘉兴网站公众号怎么开通留言功能
  • 舟山高端网站建设如何做网站结构优化
  • 垦利网站制作企业网站建设的价格
  • 上海网站制作怎么样线上引流的八种推广方式
  • 公司网站域名如何续费隧道建设杂志网站
  • 移动端网站建设原则wordpress虚拟卡密
  • 我要表白网站在线制作dedecms网站备份
  • 网站下载图标wordpress更换中文字体
  • 有的域名怎样做网站acg wordpress模板
  • 实验室网站建设方案亚马逊电子商务网站的建设
  • 骗别人做网站佛山外贸建站
  • 网站建设过程中服务器的搭建方式王烨燃大夫简介
  • 建设企业网站首页扬中做网站的公司
  • 主色调为绿色的网站青海专业网页设计免费建站