Decorator pattern
Though it is easier to write quality Go code--than quality Java code--without an understanding of the GOF design patterns, it doesn't mean that we, as Go developers, cannot benefit from GOF's insight.
We'll soon see how we can put the Decorator pattern to good use in Go.
Type hierarchy UML
This is the type hierarchy UML that we might have created while designing the Decorator pattern back in the day that we used object-oriented languages:
This is the design work needed to represent the same Decorator pattern using Go:
"Less is exponentially more"
- Rob Pike
Â
How Procedural design compares to functional Inversion of Control (IoC)
The client request is wrapped by the Authorization
, LoadBalancing
, Logging
, and FaultTolerance
 decorators. When a client request is executed, the functionality in those decorators will be injected into the flow by our Decorator framework, as shown in the following diagram:
In procedural programming, the main()
function would be in control of the flow of...