是否已建立ISomething / ISomethingable接口的替代方案? [英] Are there established alternatives to ISomething / ISomethingable for interfaces?

查看:109
本文介绍了是否已建立ISomething / ISomethingable接口的替代方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用I为接口名称添加前缀的.NET标准似乎正在变得普及,并且不再仅限于.NET。我遇到过很多使用这种约定的Java代码(因此,如果Java在C#之前使用它,我就不会感到惊讶)。 Flex也使用它,依此类推。虽然我在名字的开头放置了一个匈牙利符号,但我对使用它感到不舒服。

The .NET standard of prefixing an interface name with an I seems to be becoming widespread and isn't just limited to .NET any more. I have come across a lot of Java code that uses this convention (so it wouldn't surprise me if Java used it before C# did). Also Flex uses it, and so on. The placing of an I at the start of the name smacks of Hungarian notation though and so I'm uncomfortable with using it.

所以问题是,有没有替代方案表示Something是一个接口而不是一个类的方式,无论如何都需要表示它。或者它是否成为一个标准,所以我应该接受它并停止尝试通过建议以不同的方式做出宗教战争?

So the question is, is there an alternative way of denoting that Something is an interface, rather than a class and is there any need to denote it like this anyway. Or is it a case its become a standard and so I should just accept it and stop trying to stir up "religious wars" by suggesting it be done differently?

推荐答案

从框架设计指南书中:


表示层次结构根的接口(例如IList)也应该使用名词或名词短语。表示能力的接口应该使用形容词和形容词短语(例如IComparable,IFormattable)。

Interfaces representing roots of a hierarchy (e.g. IList) should also use nouns or noun phrases. Interfaces representing capabilities should use adjectives and adjective phrases (e.g. IComparable, IFormattable).

另外,从接口命名的注释:

Also, from the annotations on interface naming:


KRZYSZTOF CWALINA:对于接口
(如在ICollection中),使用的少数
前缀之一是I,但是这是
历史原因。回想起来,I
认为使用
常规类型名称会更好。在
的大部分情况下,案例开发人员并不关心
某些东西是一个接口而不是
抽象类,例如。

KRZYSZTOF CWALINA: One of the few prefixes used is "I" for interfaces (as in ICollection), but that is for historical reasons. In retrospect, I think it would have been better to use regular type names. In a majority of the cases developers don’t care that something is an interface and not an abstract class, for example.

BRAD ABRAMS:另一方面,接口上的I前缀是对COM
(和Java)对.NET Framework的影响的明确
的认可。 COM
普及,甚至制度化,
表示接口以I开头
。虽然我们讨论了
与这个历史模式分开
我们决定继续推进
模式,因为我们的许多用户都是
已经熟悉COM。

BRAD ABRAMS: On the other hand, the "I" prefix on interfaces is a clear recognition of the influence of COM (and Java) on the .NET Framework. COM popularized, even institutionalized, the notation that interfaces begin with "I." Although we discussed diverging from this historic pattern we decided to carry forward the pattern as so many of our users were already familiar with COM.

JEFFREY RICHTER:就个人而言,我喜欢
I前缀,我希望我们有更多
这样的东西。小的单字符
前缀对于保持
代码简洁而又具有描述性有很大帮助。正如我前面提到的b $ b,我使用
私有类型字段的前缀,因为我发现
非常有用。

JEFFREY RICHTER: Personally, I like the "I" prefix and I wish we had more stuff like this. Little one-character prefixes go a long way toward keeping code terse and yet descriptive. As I said earlier, I use prefixes for my private type fields because I find this very useful.

BRENT RECTOR注意:
这实际上是
匈牙利表示法的另一个应用程序(尽管没有
的表示符号变量名中
使用的缺点)。

BRENT RECTOR Note: this is really another application of Hungarian notation (though one without the disadvantages of the notation's use in variable names).

它已经成为一种广泛采用的标准,虽然它是匈牙利的一种形式,正如布伦特所说的那样,它没有在变量中使用匈牙利符号的缺点名字。

It has very much become a widely adopted standard, and while it is a form of Hungarian, as Brent states, it doesn't suffer from the disadvantages of using Hungarian notation in variable names.

这篇关于是否已建立ISomething / ISomethingable接口的替代方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆