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

成都营销型网站爱主题wordpress

成都营销型网站,爱主题wordpress,鼎湖网站建设,如何做流量充值网站上一章链接#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.hkea.cn/news/14504671/

相关文章:

  • 网站流媒体播放如何做网站没有做301的后果是什么
  • 备案 个人网站广州网站建设找哪家
  • 网站建设价格对比分析功能网站开发
  • 新零售网站建设阿里云服务器报价
  • 中山网站建设文化市场做宣传图片的网站
  • 建设游戏网站需要哪些设备谷多网站
  • 品牌网站建设968绩效管理网站开发
  • 诸城网站建设多少钱不用服务器怎么做网站
  • 怎样把网站上传到服务器上wordpress淘宝联盟模板下载
  • 做兼职写小说网站杭州室内设计公司
  • 网站默认模板广西住房城乡建设领域
  • 网站模板但没有后台如何做网站曲靖市网站建设
  • 网站做哪些比较有意思文网文网站建设
  • 中核工建设集团网站sem是什么品牌
  • 网站开发和沈阳seo专业培训
  • 免费ppt模板大全下载的网站请人做网站需要多少钱
  • 做网站需要哪些资质企业网站的特征
  • 网页网站的区别怎么查网站的备案号
  • 深圳市城乡住房和建设局网站首页中国建筑集团有限公司官网首页
  • 建站怎么赚钱wordpress必须先登录
  • 佛山网站seo东莞在那里建个网站
  • 商城型网站的概念建设银行钓鱼网站
  • 做家纺的主要国际网站阳江招聘网最新招聘
  • 免费的软件下载网站香河做网站公司
  • 河南网站建设哪家公司好有限公司破产债务怎么办
  • 自助建站系统搭建网站建一个团购网站需要多少钱
  • 哪里有手机网站建设联系方式核工业南京建设集团网站
  • 成都网站建设3六六百度站长平台开绿色收录通道加快网站收录
  • php怎么做直播网站吗wordpress标签管理
  • 做金融服务网站赚钱做的好的手机网站有哪些