接口命名惯例 [英] Interface naming convention

查看:253
本文介绍了接口命名惯例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这当然是主观的东西,但我没有看到任何在prefixing接口名正用我。对我来说,的事情几乎总是比更易读 IThing

This is a subjective thing of course, but I don't see anything positive in prefixing interface names with an 'I'. To me, Thing is practically always more readable than IThing.

我的问题是,为什么这个约定则存在吗?当然,它可以更容易分辨其他类型的接口。但是,那不是参数延伸到护匈牙利命名法,现在被广泛指责?

My question is, why does this convention exist then? Sure, it makes it easier to tell interfaces from other types. But wouldn't that argument extend to retaining the Hungarian notation, which is now widely censured?

什么是你该尴尬的'我'的说法?或者,更重要的是,这可能是微软的?

What's your argument for that awkward 'I'? Or, more importantly, what could be Microsoft's?

推荐答案

公约(和对他们的批评)都具有其背后的理由,让我们跑下去公约背后的一些原因

Conventions (and criticism against them) all have a reason behind them, so let's run down some reasons behind conventions


  • 接口是pfixed我区分实施的接口类型$ P ​​$ - 例如,作为上面提到需要有一个简单的方法区分事及其接口 IThing 这样的约定用于这一目的。

  • Interfaces are prefixed as I to differentiate interface types from implementations - e.g., as mentioned above there needs to be an easy way to distinguish between Thing and its interface IThing so the convention serves to this end.

接口是prefixed我从抽象类区别开来 - 有歧义,当你看到下面的code:

Interfaces are prefixed I to differentiate it from abstract classes - There is ambiguity when you see the following code:

公共类苹果:果

如果没有约定人会不知道,如果苹果继承的名为水果另一类,或者如果它是一个的实施的命名接口水果中,而 IFruit 将使这个显而易见的:

Without the convention one wouldn't know if Apple was inheriting from another class named Fruit, or if it were an implementation of an interface named Fruit, whereas IFruit will make this obvious:

公共类苹果:IFruit

最惊喜的原则也适用。

不匈牙利命名法的所有用途都指责 - 匈牙利命名法的早期应用,标志着一个preFIX这说明对象的类型,然后后面是变量名称或有时一个在变量名前下划线。这是,对于某些编程环境(认为的Visual Basic 4 - 6)是有用的,但作为真正的面向对象的程序设计在普及成为不切实际和冗余指定类型增长。这成为问题,尤其是当它来到智能感知。

Not all uses of hungarian notation are censured - Early uses of Hungarian notation signified a prefix which indicated the type of the object and then followed by the variable name or sometimes an underscore before the variable name. This was, for certain programming environments (think Visual Basic 4 - 6) useful but as true object-oriented programming grew in popularity it became impractical and redundant to specify the type. This became especially issue when it came to intellisense.

今天匈牙利命名法是可以接受的区分实际数据的UI元素,同样相关的UI元素,例如 txtObject 为一个文本框, lblObject 为与该文本相关联的,而对于文本框的数据只是标签对象

Today hungarian notation is acceptable to distinguish UI elements from actual data and similarly associated UI elements, e.g., txtObject for a textbox, lblObject for the label that is associated with that textbox, while the data for the textbox is simply Object.

我也不得不指出的是,原来使用匈牙利命名法不是用来指定数据类型(称为系统匈牙利命名法),而是指定语义使用一个变量名(被称为应用匈牙利表示法)的。了解更多关于这对匈牙利命名法的维基百科条目。

I also have to point out that the original use of Hungarian notation wasn't for specifying data types (called System Hungarian Notation) but rather, specifying the semantic use of a variable name (called Apps Hungarian Notation). Read more on it on the wikipedia entry on Hungarian Notation.

这篇关于接口命名惯例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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