So the decorator pattern allows you to add behaviour to a class dynamically, right? However, the decorator has to be inherited from the base class of the class getting the behaviour or must implement one of its interfaces. Indeed, all the examples I can recall have had one exposed function so applying a decorator works well however what if you want to make a decorator to add behaviour such as logging to various classes that no not have the same interface- it won't work. Am I missing something here? Is this a hint that all classes that I would want to log SHOULD be wrapped in the same interface, like a command or something?
For example
class A { whatever(); idontknow(); } class B { bananas(); } I can't make a decorator to log the calls of the functions in these classes because they are different.