How to structure interfaces in application directory hierarchy?

 ̄綄美尐妖づ 提交于 2019-12-08 01:48:15

问题


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


回答1:


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.


来源:https://stackoverflow.com/questions/2401466/how-to-structure-interfaces-in-application-directory-hierarchy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!