So decorators wrap a base class recursively, right? And have a single super class object which is at the "core" class.
Couldn't you just add an ArryList/LinkedList of decorations in the "core" class and achieve the same thing? This would avoid recursion (which is expensive), but allow the dynamic behavior of being able to "decorate" your classes.
Is this a different pattern or an alternative version of decorators or something else?
Ex:
Decorator
Beverage class
getDescription(){blah}
cost();
HouseBlend inherits from Beverage
cost(){2.99}
CondimentDecorator inherits from Beverage
Beverage bev;
cost(){.19 + bev.cost}
getDescription{blah}
VS
Other?
Beverage class
getDescription(){blah}
cost();
HouseBlend inherits from Beverage
List<Beverage> condiments
cost(){2.99 + iterative condiments}
CondimentDecorator inherits from Beverage
cost(){blah}
getDescription{blah}
It seems like the decorator might be a little more flexible, but the other version would allow you to keep track of specific instances of items. Also, if you had espresso you could have a double shot, where with a pure decorator that would be hard.