-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCream.java
More file actions
22 lines (17 loc) · 765 Bytes
/
Copy pathCream.java
File metadata and controls
22 lines (17 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/* If you look back at the our class diagram, you’ll see we’ve now written our abstract component (Coffee),
we have our concrete components (Filter and Instant), and we have our abstract decorator (AddOnDecorator).
Now it’s time to implement the concrete decorators.
*/
//Cream is decorator so it extends AddOnDecorator and AddOnDecorator extends Coffee
public class Cream extends AddOnDecorator{
Coffee coffee; //Instantiating Cream with a reference to a Coffee
public Cream(Coffee coffee){
this.coffee=coffee;
}
public String getDescription(){
return coffee.getDescription()+ ", Cream";
}
public double cost(){
return 25+coffee.cost(); //Add the cost of the decorator with the coffee
}
}