为什么前缀C#接口与“我”的名字 [英] Why prefix C# interface names with an “I”

查看:108
本文介绍了为什么前缀C#接口与“我”的名字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是什么命名约定背后的原因是什么?

What is the rationale behind this naming convention?

我看不到任何好处。额外的前缀只是污染了API。

I don't see any benefit. The extra prefix just pollutes the API.

我的想法是内嵌康拉德的响应来此相关的问题;所选择的回答其中大部分是什么,我要求在这里。

My thinking is inline with Konrad's response to this related question; the chosen answer of which is mostly what I am asking for here.

推荐答案

它完全相反,命名约定清楚地标识一个接口

Its the complete opposite, the naming convention clearly identifies an interface.

例如,如果您有:

{
....


For example if you have:

public class Dog : IPet, IMammal
{
    ....

刚刚从阅读它,我可以有把握地认为IPET和IMammal可能接口。

Just from reading it, I can safely assume that IPet and IMammal are probably interfaces.

在.NET CLR允许单个类继承。所以,如果我有一个基地class..I只能从它继承一个类。让我们改变IPET接口基地class..our比如现在变成

The .NET CLR allows for single class inheritance. So, if I have a base class..I can only inherit one class from it. Lets change the IPet interface to a base class..our example now becomes

public class Dog : Pet, IMammal
{
    ....

我从宠物类继承和实施IMammal接口

I am inheriting from the Pet class and implementing the IMammal interface.

如果我们做到了你的建议是什么,并删除了字母I我们有这样的:

If we did it what you are suggesting and removed the letter "I" we have this:

public class Dog : Pet, Mammal
{
    ....

哪一个是我从继承类?这是我实现的接口?它变得混乱吧? (FYI..you应该把基类永远第一,所以你可能会说这一点......但如果​​你在争论从接口前缀名称中删除信我,我怀疑你遵循这一做法也一样)

Which one is the class I am inheriting from? Which is the interface I am implementing? It gets confusing right? (FYI..you are supposed to put the base class always first, so you could argue that point...but if you are arguing to remove the letter I from prefixing interface names I doubt you follow that practice as well)

正如你可以看到轻松的命名规则告诉我很多关于我的对象,而我不必进一步调查。我可以很容易地看到什么,我继承了VS什么,我实现。

As you can see that naming convention easily tells me a lot about my object without me having to investigate further. I can easily see what I am inheriting vs what I am implementing.

这篇关于为什么前缀C#接口与“我”的名字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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