如何构建应用程序的目录层次结构中的接口?应用程序、层次、接口、结构

由网友(小熊咕嘟咕嘟开锅.)分享简介:把他们都在一个单独的文件夹结构或与类它实现呢? Put them all in one separate folder structure or along with classes which implements them ? 推荐答案您永远不应该把接口与实现它们(除非这些类fulfull下列要求)的类。否则...

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

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.
阅读全文

相关推荐

最新文章