Decorative pattern in Python allows to wrap the core object with other object capable of changing its behavior. It is also suggested that monkey-patching can be used to achieve similar effect? How does two compare? When is decorative pattern more useful than monkey-patching when used for the same task?
Decorative pattern in Python allows to wrap the core object with other object capable
Share
The main difference between using the decorative pattern and monkey patching is that monkey patching can lead to hard-to-debug code. The problem is that monkey patching does not explicitly show the fact that you modified the class: users/readers/maintainers might be confused by the fact that the patched class behaves differently from what they expect (i.e. from the original class). I would recommend sticking to the decorative pattern, for code maintainability.