Some design patterns (mentioned, not explained)
we have seen that we can give objects attributes through associations (as we did with the color). Your object may have a fixed number of attributes, such as color, flavor, material, texture, and so on. For each attribute there is a place where it is stored.
But what if there is a variable number of attributes, which in a way augment each other? That’s where a Decorator pattern comes in. It allows to deal with a variable number of attributes which add their behavior, and also with attributes which were not yet known when the class was designed.
Example: Text with attributes
plain text bold text bold+italic text
underlined text bold underlined bold underlined and italic
shadow underlined text bold underlined bold underlined and italic
This is a good example where a decorator is useful, because we might have attributes which we did not think of before (such as a “small caps” attribute).