120 likes | 467 Views
Ice Cream Model. If( f.equals( “vanilla” ) ){ // do something }else if ( f.equals( “chocolate” ) ){ // do something else } Cream aCream = new Cream(); aCream.setFlavor( “vanilla” );. Cream. - flavor: String - toppings: String - price: float … . + setFlavor( f: String ): void.
E N D
Ice Cream Model • If( f.equals(“vanilla”) ){ // do something}else if ( f.equals(“chocolate”) ){ // do something else} • Cream aCream = new Cream();aCream.setFlavor(“vanilla”); Cream - flavor: String - toppings: String - price: float … + setFlavor(f: String): void Let’s not do this. Have your complier work harder!
If( f.equals(“vanilla”) ){ // do something}else if ( f.equals(“chocolate”) ){ // do something else} • Cream aCream = new Cream();aCream.setFlavor(“vanilla”); Cream - flavor: String - toppings: String - price: float … + setFlavor(f: String): void If( f.equals(Flavor.VANILLA) ){// do something } else if( f.equals(Flavor.VANILLA) ){// do something else } Cream aCream = new Cream(); aCream.setFlavor(Flavor.VANILLA); Cream <<enumeration>> Flavor - flavor: Flavor - toppings: String - price: float … 0..* VANILLACHOCOLATESTRAWBERY LIME ORANGE 1 + setFlavor(f: Flavor): void
Cream <<enumeration>> Flavor 0..* 1 - flavor: Flavor - toppings: Topping[] - price: float … VANILLACHOCOLATESTRAWBERY LIME ORANGE 0..* + setFlavor(f: Flavor): void + setToppings(t: Topping[]): void <<enumeration>> Topping 0..* NUTSEXTRACHOCOLATESTRAWBERRYJEERRY
Cream <<enumeration>> Flavor 0..* 1 - flavor: Flavor - toppings: Topping[] - price: float … VANILLACHOCOLATESTRAWBERY Class diagram + setFlavor(f: Flavor): void + setToppings(t: Topping[]): void myCream: Cream vanilla: Flavor Flavor.VANILLA Object diagram yourCream: Cream chocolate: Flavor Flavor.CHOCOLATE : Cream strawberry: Flavor Flavor.STRAWBERY
Now, We can Make these Ones. Cream <<enumeration>> Flavor 0..* 1 - flavor: Flavor - toppings: Topping[] - price: float … VANILLACHOCOLATESTRAWBERY LIME ORANGE 0..* + setFlavor(f: Flavor): void + setToppings(t: Topping[]): void <<enumeration>> Topping 0..* NUTSEXTRACHOCOLATESTRAWBERRYJEERRY
How about these ones? http://www.graniteschools.org/jr/eisenhower/images/memorie%20pics/world_records/Tallest_Ice_Cream_Cone.jpg
up 0..1 Cream <<enumeration>> Flavor 0..* 1 - flavor: Flavor - toppings: Topping[] - price: float … VANILLACHOCOLATESTRAWBERY LIME ORANGE down 0..* 0..1 + setFlavor(f: Flavor): void + setToppings(t: Topping[]): void Class diagram <<enumeration>> Topping 0..* NUTSEXTRACHOCOLATESTRAWBERRYJEERRY 3rdCream: Cream vanilla: Flavor up Flavor.VANILLA Object diagram down 2ndCream : Cream chocolate: Flavor up Flavor.CHOCOLATE down 1stCream : Cream strawberry: Flavor
1 <<enumeration>> Flavor Cream 1 - flavor: Flavor - toppings: Topping[] - price: float … VANILLACHOCOLATESTRAWBERY LIME ORANGE 0..* - scoops 0..* 0..* + setFlavor(f: Flavor): void + setToppings(t: Topping[]): void <<enumeration>> Topping 0..* NUTSEXTRACHOCOLATESTRAWBERRYJEERRY - cone 1 0..1 Cone 0..*
How about these cases? Cone or cup Size of cone/cup
<<enumeration>> Flavor Cream 1 - flavor: Flavor - toppings: Topping[] - price: float … VANILLACHOCOLATESTRAWBERY LIME ORANGE 0..* - scoops 0..* 0..* + setFlavor(f: Flavor): void + setToppings(t: Topping[]): void <<enumeration>> Topping 0..* - scoops 0..* NUTSEXTRACHOCOLATESTRAWBERRYJEERRY - cup 0..1 0..1 - cone 0..1 0..* Cup Cone 0..* 0..* <<enumeration>> Size SMALLMEDIUM LARGE 1 - size
<<enumeration>> Flavor Cream 1 - flavor: Flavor - toppings: Topping[] - price: float … VANILLACHOCOLATESTRAWBERY LIME ORANGE 0..* - scoops 0..* 0..* + setFlavor(f: Flavor): void + setToppings(t: Topping[]): void <<enumeration>> Topping 0..* 1 - base NUTSEXTRACHOCOLATESTRAWBERRYJEERRY Base (Lower Part) 0..* - size: Size - scoops: Cream[] - price: float - topping: Topping … - size 1 0..1 <<enumeration>> Size SMALLMEDIUM LARGE Cup Cone 0..*