开发者

How to structure interfaces in application directory hierarchy?

Put them all in on开发者_StackOverflowe separate folder structure or along with classes which implements them ?


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.

You basically have two options:

  • 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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜