如何构建应用程序的目录层次结构中的接口? [英] How to structure interfaces in application directory hierarchy?

查看:191
本文介绍了如何构建应用程序的目录层次结构中的接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

把他们都在一个单独的文件夹结构或与类它实现呢?

Put them all in one separate folder structure or along with classes which implements them ?

推荐答案

您永远不应该把接口与实现它们(除非这些类fulfull下列要求)的类。否则,将推出的紧耦合的接口和执行者之间,你将无法创建接口的其他实现不simulataneously引用实施者。

You should never put interfaces together with the classes that implement them (unless those classes fulfull the requirements below). Doing that will introduce a tight coupling between the interface and the implementer, and you will not be able to create other implementations of the interface without simulataneously referencing the implementer.

您基本上有两种选择:

  • 将接口与类的消耗他们。这仍产生一个紧耦合,但是这种耦合是少问题的,因为消费者往往生活在一个库,提供相关的类型。在这种情况下,如果你有实施者此库,就可以实现的接口没有引入任何附加耦合。
  • 对于最终的松耦合,把接口在一个单独的库。这给了你更大的灵活性,但也可能需要一些额外的工作。
  • Put the interfaces together with the classes consuming them. This still creates a tight coupling, but this coupling is less problematic, as the consumers often live in a library that provides related types. In this case, if you have implementers in this library, they can implement the interfaces without introducing any additional coupling.
  • For the ultimate in loose coupling, put the interfaces in a separate library. This gives you greater flexibility, but may also requires a bit extra work.

这篇关于如何构建应用程序的目录层次结构中的接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆