How do I name an interface when the base word star

2019-04-03 12:14发布

I want to create an interface for "Items". Typicaly I would name an interface by adding and "I" prefix to a base word. But in this case my base word already starts with an I. Here are a couple ideas I've had

  • IItem: Two I's
  • Iitem : Vary the case
  • ItemInterface: Skip the I prefix and write out Interface

What looks the best? Has anyone else run into this problem. If so what did you do?

5条回答
Juvenile、少年°
2楼-- · 2019-04-03 12:39

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

查看更多
时光不老,我们不散
3楼-- · 2019-04-03 12:43

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.

查看更多
Explosion°爆炸
4楼-- · 2019-04-03 12:44

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.

查看更多
对你真心纯属浪费
5楼-- · 2019-04-03 12:55

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

查看更多
手持菜刀,她持情操
6楼-- · 2019-04-03 12:56

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.

查看更多
登录 后发表回答