官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 海安县| 浦城县| 阳山县| 志丹县| 十堰市| 朝阳市| 策勒县| 沾化县| 凤城市| 澄城县| 高密市| 綦江县| 曲沃县| 泌阳县| 海原县| 潞城市| 宜丰县| 鄂州市| 增城市| 会同县| 聊城市| 南康市| 浦城县| 繁峙县| 伊宁县| 乐业县| 柯坪县| 彭州市| 郓城县| 清苑县| 陵水| 甘谷县| 隆回县| 珲春市| 鞍山市| 雷山县| 潢川县| 阿尔山市| 通江县| 晋江市| 迁西县|