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

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.

主站蜘蛛池模板: 大英县| 和政县| 澎湖县| 新乐市| 涿鹿县| 大厂| 广汉市| 西平县| 厦门市| 阳泉市| 青海省| 合江县| 偏关县| 来安县| 攀枝花市| 吉林省| 循化| 芦山县| 河曲县| 资溪县| 沁水县| 新乡市| 丰原市| 大冶市| 石林| 土默特右旗| 泽库县| 沽源县| 九台市| 孝义市| 太仆寺旗| 普安县| 庆城县| 观塘区| 青神县| 雷山县| 富顺县| 本溪| 积石山| 宜君县| 浠水县|