-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathEx.java
50 lines (39 loc) · 1.72 KB
/
Ex.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package Structural.Composite.Example.With_Iterator;
/*
* This example is violates the Interface Segregation principle,
* but for transparency of the code.
* (Client always work with MenuComponent,
* so he can not ot worry about the instanceOf() )
* But he also need catch the exception.
*/
import Structural.Composite.Example.With_Iterator.Restoran.Menu.Menu;
import Structural.Composite.Example.With_Iterator.Restoran.MenuComponent;
import Structural.Composite.Example.With_Iterator.Restoran.MenuItem.Dish;
import Structural.Composite.Example.With_Iterator.Restoran.Waitress;
//Some menus may have a different menu in the himself
// Security is low bc he can use add(MenuComponent) in Dish, which not good
public class Ex {
public static void main(String[] args) {
//Create Menus
MenuComponent desertMenu1 = new Menu("Desert in haven menu");
MenuComponent desertMenu2 = new Menu("Special propose menu");
MenuComponent desertMenu3 = new Menu("Christmas menu");
MenuComponent dinnerMenu = new Menu("Dinner for Gentlemen");
//Adding item to mainMenu (top of the tree)
MenuComponent mainMenu = new Menu("Main menu : ");
mainMenu.add(desertMenu1);
mainMenu.add(dinnerMenu);
Waitress waitress = new Waitress(mainMenu);
//Adding item to another elements
desertMenu1.add(new Dish("Waffles", 0.99));
desertMenu1.add(new Dish("Desert", 2.90));
desertMenu1.add(desertMenu2);
desertMenu2.add(new Dish("Pancake with milk", 5.25));
desertMenu2.add(desertMenu3);
desertMenu3.add(new Dish("Santa sperm", 0.01));
dinnerMenu.add(new Dish("HotDog", 3.99));
dinnerMenu.add(new Dish("BLT", 10.99));
dinnerMenu.add(new Dish("Soup", 7.99));
waitress.getMenuWithMinPrice(5.00);
}
}