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

福州短视频seo网站太原seo哪家好

福州短视频seo网站,太原seo哪家好,专门做衬衣网站,网站做推广百度好还是360好上一章链接: 《HeadFirst设计模式(第二版)》第九章代码——迭代器模式_轩下小酌的博客-CSDN博客 前面说到,当一个菜单里面出现了子菜单的时候,前面的迭代器模式得换成组合模式。 组合模式: 允许将对象组合成树形结构来表现部分-整…

上一章链接:

《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{//菜单组合ArrayList<MenuComponent> menuComponents = new ArrayList<MenuComponent>();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("---------------------");//这里递归打印Iterator<MenuComponent> 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("K&B's 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.yidumall.com/news/94812.html

相关文章:

  • f2fpay wordpress合肥seo代理商
  • vr看房网站开发费用常州网站建设书生商友
  • 临沂网站建设那家好临安网站seo
  • 品牌策划网站建设互联网营销师考试题及答案
  • 北京网站制作建设公司网站收录免费咨询
  • 建设网站最快多长时间百度数据中心
  • 南昌网站设计特色最新的疫情防控政策和管理措施
  • 专门做酒店网站湖南网站建设加盟代理
  • 谈谈你对网站建设有什么样好的建设意见引擎搜索优化
  • 怎么把自己做的网站放到网上国内5大搜索引擎
  • 做电影下载网站需要什么软件市场营销培训课程
  • 美国美女做愛网站seo网站
  • 网站建设方案主要是seo优化网
  • 资产管理wordpress广东网络seo推广公司
  • 昆明网站建设推广服务免费网站搭建
  • 外贸批发网站建设网站搭建的流程
  • wordpress调用会员等级唐山seo推广公司
  • 网站可以用什么做百度经验登录入口
  • 怎样找人做网站拉新任务接单放单平台
  • 做自己的网站的一般步骤爱站网能不能挖掘关键词
  • 舟山论坛网站建设新媒体营销六种方式
  • 网站策划书ppt身边的网络营销案例
  • 扬州市建设厅网站app开发费用一般多少钱
  • 联想企业网盘上海seo
  • 宝塔wordpress开启https武汉标兵seo
  • 同性恋色做视频网站有哪些网站seo优化步骤
  • 网页设计精选网站百度网页高级搜索
  • 烟台建设工程施工图审查系统网站湖南seo优化报价
  • 安徽省六安市建设局网站百度官网
  • 网站做多个页面torrentkitty磁力官网