Jump to: navigation, search


6 bytes added, 14:19, 28 February 2007
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());

Navigation menu