- 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.
- 信息可視化的藝術(shù):信息可視化在英國
- OpenCV 3和Qt5計(jì)算機(jī)視覺應(yīng)用開發(fā)
- 深入理解Java7:核心技術(shù)與最佳實(shí)踐
- 征服RIA
- Java軟件開發(fā)基礎(chǔ)
- 網(wǎng)店設(shè)計(jì)看這本就夠了
- Java程序設(shè)計(jì):原理與范例
- HTML5入門經(jīng)典
- 前端HTML+CSS修煉之道(視頻同步+直播)
- Android應(yīng)用案例開發(fā)大全(第二版)
- Android開發(fā)三劍客:UML、模式與測(cè)試
- 響應(yīng)式Web設(shè)計(jì):HTML5和CSS3實(shí)戰(zhàn)(第2版)
- Android應(yīng)用開發(fā)實(shí)戰(zhàn)(第2版)
- Visual C++開發(fā)寶典
- Web前端開發(fā)最佳實(shí)踐