tailieunhanh - head first design patterns phần 7

Đi một đối tượng DarkRoast trang trí nó với một đối tượng Mocha Trang trí với một đối tượng Whip Gọi chi phí () và dựa trên đoàn để thêm vào các chi phí gia vị Được rồi, nhưng làm thế nào để bạn "trang trí" một đối tượng, và làm thế nào để đoàn đại biểu đi vào điều này? Một gợi ý: suy nghĩ của | composite responsibilities Getting ready for a test drive. N0T this output is based on the Complete source java MenuTestDrive ALL MENUS All menus combined - Here s all our menus. we printed all this PANCAKE HOUSE MENU Breakfast just by calling prmto on the top level menu KiB s Pancake Breakfast v Pancakes with scrambled eggs and toast Regular Pancake Breakfast Pancakes with fried eggs sausage Blueberry Pancakes v Pancakes made with fresh blueberries and blueberry syrup Waffles v Waffles with your choice of blueberries or strawberries DINER MENU Lunch Vegetarian BLT v Fakin Bacon with lettuce tomato on whole wheat BLT Bacon with lettuce tomato on whole wheat Soup of the day A bowl of the soup of the day with a side of potato salad Hotdog A hot dog with saurkraut relish onions topped with cheese Steamed Veggies and Brown Rice v Steamed vegetables over brown rice Pasta v Spaghetti with Marinara Sauce and a slice of sourdough bread DESSERT MENU Dessert of course Apple Pie v Apple pie with a flakey crust topped with vanilla icecream Cheesecake v Creamy New York cheesecake with a chocolate graham crust Sorbet v A scoop of raspberry and a scoop of lime The new dessert menu is printed when we arc printing all the Diner menu Components CAFE MENU Dinner Veggie Burger and Air Fries v Veggie burger on a whole wheat bun lettuce tomato and fries Soup of the day A cup of the soup of the day with a side salad Burrito v A large burrito with whole pinto beans salsa guacamole 366 Chapter 9 the iterator and composite patterns What s the story First you tell US 0 c One Class. One Responsibility and now you y are giving US a pattern with two responsibilities k in one class. The Composite Pattern manages I a hierarchy AND it performs operations X. related to Menus. _ S There is some truth to that observation. We could say that the Composite Pattern takes the Single Responsibility design principle and trades .