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

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.

主站蜘蛛池模板: 湖口县| 锡林浩特市| 和顺县| 三都| 忻州市| 宁武县| 当雄县| 中方县| 阳朔县| 浦县| 巴林左旗| 寻乌县| 离岛区| 定西市| 罗甸县| 龙川县| 平泉县| 河间市| 鹿邑县| 米脂县| 安吉县| 澄城县| 扎兰屯市| 康定县| 榕江县| 喀喇沁旗| 思南县| 和林格尔县| 玉林市| 称多县| 包头市| 灵台县| 锦州市| 大田县| 通海县| 潞西市| 柳州市| 永川市| 会宁县| 晋中市| 固安县|