Lecture 5&6
Lecture 5&6
Refactoring
Instructor:(Awais(Qasim
The$Decorator$Pattern
Example:)StarBuzz)Coffee
BEVERAGE
description
get_description()
cost()
Component
methodA()
methodB()
//other methods
component
ConcreteComponent Decorator
methodA() methodA()
methodB() methodB()
//other methods //other methods
ConcreteDecoratorA ConcreteDecoratorB
Component wrapped Object Component wrapped Object
Object newState
methodA()
methodB()
newBehavior() methodA()
//other methods methodB()
//other methods
Starbuzz(Coffee(Example
Beverage
description
getDescription()
cost()
//other methods
component
CondimentDecorator
HouseBlend DarkRoast Espresso Decaf getDescription()
cost() cost() cost() cost()
Write and compile the code for the other Soy and Whip
condiments. Youll need them to finish and test the
application.
Writing'the'Starbuzz'code
Output
The$Decorator$Pattern
The decorated object and the original object have the
same type. Thus, the decorated object can be passed
instead of the original object.