简体   繁体   English

解决方案中的多个项目:接口命名约定

[英]Multiple projects within a solution: Interface naming convention

I was wondering what the naming convention for an Interface sub project within a solution would be. 我想知道解决方案中的Interface子项目的命名约定是什么。 I know interface files start with an "I", does this apply to projects as well? 我知道接口文件以“I”开头,这是否也适用于项目?

I have separated the interface into a separate project to keep the solution organised, as opposed to creating a interface file within the project which would be implementing the interface. 我已将接口分离为单独的项目以保持解决方案的有序性,而不是在项目中创建将实现接口的接口文件。

All files and projects are contained within one solution. 所有文件和项目都包含在一个解决方案中。

I apologise if this doesn't read well. 如果这不好读,我道歉。

This is a common pattern for organizing solutions with many projects. 这是组织许多项目解决方案的常见模式。 However, there is some debate whether (in some cases) it is worth it. 然而,是否(在某些情况下)是否值得,存在一些争论。

I've seen a few different naming conventions used: 我见过几种不同的命名约定:

  1. Inc.Project.Contract Inc.Project.Contract
  2. Inc.Project.Contracts Inc.Project.Contracts
  3. Inc.Project.Interface Inc.Project.Interface
  4. Inc.Project (like a base project that is a common dependency) Inc.Project(就像一个共同依赖的基础项目)
  5. Inc.Project.Common Inc.Project.Common

This is the way MS uses it <Company>.(<Product>|<Technology>)[.<Feature>][.<Subnamespace>] 这是MS使用它的方式<Company>.(<Product>|<Technology>)[.<Feature>][.<Subnamespace>]

For example, Microsoft.WindowsMobile.DirectX. 例如, Microsoft.WindowsMobile.DirectX. see link http://msdn.microsoft.com/en-us/library/ms229026.aspx 请参阅链接http://msdn.microsoft.com/en-us/library/ms229026.aspx

I agree with the naming convention that dtryon wrote in its answer. 我同意dtryon在其答案中所写的命名约定。

But do not over-engineer the design of your solution. 但是,不要过度设计解决方案的设计。 If you don't need to reference your interface from multiple projects, I don't think separating your interface in its own project is useful. 如果您不需要从多个项目引用您的界面,我不认为在自己的项目中分离您的界面是有用的。 It adds complexity but very few benefits. 它增加了复杂性但很少有好处。

Same thing for the interface file itself: if you do not plan to reference an object instance using the interface type (and not the type of the object that actually implements the interface), the interface isn't really useful. 接口文件本身也是如此:如果您不打算使用接口类型(而不是实际实现接口的对象的类型)引用对象实例,则该接口实际上并不实用。

I usually follow a pattern of ... 我通常遵循......的模式

  1. MyAppSolution - empty solution MyAppSolution - 空解决方案
  2. MyApp.App - client facing application MyApp.App - 面向客户的应用程序
  3. MyApp.Adapters - project containing interfaces MyApp.Adapters - 包含接口的项目
  4. MyApp.DAL - the data access layer MyApp.DAL - 数据访问层

That's usually as simple as I make it ... If things are more complex, I may have a services project or a business rules project or something of that nature ... the reason I use an interface project is that I want the client application to be completely ignorant of the back end implementation; 这通常就像我做的那样简单......如果事情变得更复杂,我可能有一个服务项目或业务规则项目或者那种性质......我使用接口项目的原因是我想要客户端应用程序完全不了解后端的实现; that way if I need to change an implementation, the client is not affected (does not have to change) as long as I don't change the interfaces ... And, this really happens ... I have changed DBMS's before, I have changed from a DBMS to an API, etc ... When initially building out an app, the extra layer of abstraction can seem like overkill until you need it, then it is a god send ... 这样,如果我需要更改一个实现,只要我不更改接口,客户端就不会受到影响(不必更改)...而且,这确实发生了......我之前已经更改了DBMS,我已经从DBMS变为API等...当最初构建一个应用程序时,额外的抽象层看起来有点矫枉过正,直到你需要它,然后它是一个神派...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM