Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending the functionality
Let's make up a simplistic example that couple of library would like to complement each other. We have three library so-called React, Vue and Angular. We want to combine functionalities of these library in whatever order as long as all library could do their own work on single call from client code. First of all, let's standardize a single interface for all libraries to implement upon
Then following by concrete implementation of React, Vue and Angular struct that know how to work either alone or with another of the same kind
And there we have the Decorator Pattern implemented in Go. This pattern is one of my favorite patterns as it is so practice and I have seen many usage in software development. For example, the followings make use of the Decorator Pattern:
P/s: The accompany code is included in this PR 😊
Happy coding 😎