How do I name an interface when the base word starts with an I?

我怕爱的太早我们不能终老 提交于 2019-12-03 22:14:59

Although hard to read, IItem would be in line with some existing "II" interfaces:

Simply IItem. There is no need for an exception.

Interfaces start with two upper case letters (I[A-Z]), which identify them as an interface. So Item is not an interface, but IItem is.

According to .Net naming convention Interface name should be preceded by Capital Letter 'I' Followed by Name of interface in Camel case.

So I suggest you to to name interface Item as:

IItem

Not necessary to Mention 'Interface' at the end because The Letter 'I' at the Start itself says that it is Interface, not require to mention explicitly.

You can see the MS guys is using System.ComponentModel.IItemProperties

Edit 2016/08/12: I originally provided this answer as an alternative perspective on naming conventions. My day-to-day C# now uses I-prefixing to keep things idiomatic and to reduce cognitive burden through consistency. I think consistency is more important than the issues I raise below. In short, stick with the conventions of the code base you're working in.


Just Item. Not because the interface starts with an I, but rather because prefixing classes with identifying letters is not necessary. Decorating interfaces with I is as ugly as slapping C before your concrete class names (a la MFC). Prefixing types with anything is as bad as using Hungarian notation.

You could argue that it actually gives you semantic value, but I'm not convinced. I have a modern IDE and I don't need my type names to be any more complex.

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