I have a Composite object (A tree structure) and I would like to add a Decorator that is applied to each object that is part of the tree structure. is this possible? Here are several use cases:
A composite shape, having the function draw(). I would like to apply the "blue" decorator, so that when I call "draw", all sub-shapes are drawn blue.
Advanced (Might require also a Visitor pattern): A composite MathExpression, where the leaves are numbers and the internal nodes are operations. I would like to add a decorator that whenever it encounters a number, it increments it, and whenever it encounters an operation, it doubles the result. for example, if the expression is (3+5)-2, the decorated expression would be 2*(2*((3+1)+(5+1))-(2+1))