Advantages of monkey patching

Monkey patching as a form of DI is very different from the other methods presented in this book in both implementation and effect. As such, there are some situations in which monkey patching is either the only option or the only succinct one.  Monkey patching's other advantages are detailed in this section.

DI via monkey patching is cheap to implement—In this book, we have talked a lot about decoupling, which is the idea that separate pieces of our code should be kept separate, even though they use/depend on each other. We introduce abstractions and inject them into each other. Let's step back for a moment and consider why we want the code decoupled in the first place. It's not only about making it easier to ...

Get Hands-On Dependency Injection in Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.