Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it.
Let's go for a quick example. We have an imaginary workflow as following. The UI get render in order React -> Vue -> Angular -> Done. Any step might be escaped and move on next only if the proper property set to be done. Simple enough, let's first define a standard interface for the chain's components to follow
Next, we want to code up React, Vue and Angular libraries accordingly to the defined interface as below
And the final key to mark the end of the workflow
And the UI struct to attach multiple steps indicate whether responsibility has been fulfilled
There we go - the Chain Of Responsibility Pattern implemented in Go. This pattern provide strong single responsibility and open/closed principles. The only drawback is that multiple handlers might get unhandled which most of the time might not be an issues since its only job is to forward the request to the next handler in the chain.
P/s: The accompany code is included in this PR 😊
Happy coding 😎