- Hands-On Dependency Injection in Go
- Corey Scott
- 162字
- 2021-06-10 19:17:49
What does this mean for Go?
We have talked before about Go's support for implicit interfaces and how we can leverage that to define our dependencies as interfaces in the same package, rather than importing an interface from another package. This approach is DIP.
Perhaps your inner skeptic is going crazy, yelling, but this would mean I would have to define interfaces everywhere! Yes, that might be true. It could even result in a small amount of duplication. You will find, however, that the interfaces you would have defined without dependency inversion would have been fatter and more unwieldy, a fact that would have cost you more to work with in the future.
After applying DIP, you are unlikely to have any circular dependency issues. In fact, you will almost certainly find that the number of imports in your code drops significantly and your dependency graph becomes rather flat. In fact, many packages will only be imported by the main package.
- Raspberry Pi for Python Programmers Cookbook(Second Edition)
- Progressive Web Apps with React
- Java技術手冊(原書第7版)
- Amazon S3 Cookbook
- 學Python也可以這么有趣
- 大模型RAG實戰:RAG原理、應用與系統構建
- Python忍者秘籍
- SQL經典實例(第2版)
- Integrating Facebook iOS SDK with Your Application
- 軟件項目管理實用教程
- Android應用開發實戰(第2版)
- Python一行流:像專家一樣寫代碼
- Spark技術內幕:深入解析Spark內核架構設計與實現原理
- Java程序設計
- Mastering Vim