Question: Review the following code snippets from a Java class implementing the Decorator Design Pattern. Select the option that incorrectly implements a component or method of

Review the following code snippets from a Java class implementing the Decorator Design Pattern. Select the option that incorrectly implements a component or method of this pattern.
(Note: The question assumes familiarity with the Decorator Design Pattern, which involves a base class and decorators that modify the behavior of base class instances. The correct implementation involves all decorators extending a common abstract decorator class and modifying base class behavior.)
Option A.
public abstract class Beverage {
String description = "Unknown Beverage";
public String getDescription(){
return description;
}
public abstract double cost();
}
Option B.
public class Espresso extends Beverage {
public Espresso(){
description = "Espresso";
}
public double cost(){
return 1.99;
}
}
Option C.
public abstract class CondimentDecorator extends Beverage {
public Beverage beverage;
public abstract String getDescription();
}
Option D.
public class Milk extends Beverage {
Beverage beverage;
public Milk(Beverage beverage){
this.beverage = beverage;
}
public String getDescription(){
return beverage.getDescription()+", Milk";
}
public double cost(){
return .10;
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!