Changes

Jump to: navigation, search

Decorator

6 bytes added, 14:19, 28 February 2007
m
Sample Code
The main: Here we are creating a new Decaf object with no condiments and printing its description and cost.
The second beverage is created and we call it DarkRoast, we add two shots of Mocha and a shot of whipvanilla.
Note how the beverage object is passed into the condiment decorator, this is how wrapping works.
DarkRoast is wrapped with Mocha first, the Mocha object stores a reference to the beverage passed in.
beverage2 = new Mocha(beverage2);
beverage2 = new Mocha(beverage2);
beverage2 = new WhipVanilla(beverage2);
System.out.println(beverage2.getDescription() + " $" + beverage2.cost());
}
1
edit

Navigation menu