当名称已经以大写字母开头时的名称接口约定
假设我想为一个名为 JQuery 的类创建一个接口。
如果这个类是一个接口,按照约定,我应该将其命名为 IJQuery,但我发现它使这个名称看起来很奇怪。
你认为呢 ?
Let say I want to create an interface for a class that should be name JQuery.
If this class is an interface, from the conventions, I should name it IJQuery, but I find it's made the name look weird.
What you think ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我从来不热衷于将对象类型的信息嵌入到其名称中,因此我无论如何都不会使用
I
作为前缀。但是,如果您这样做,遵守约定是个好主意,但根据您的示例,我还会考虑如何命名接口,因为据我所知,您将有一个IJQuery
和一个 JQueryImpl。我会考虑将您的界面命名为
JavaScriptLibrary
之类的名称,然后将您的实现类命名为JQuery
或Prototype
。在爪哇中:
I've never been a big fan of embedding information of the type of an object into its name, so I would not use
I
as a prefix anyway. But if you are doing it is a good idea to keep with the convention, but based on your example I would also consider how you name your interfaces, because from what I can tell you would have anIJQuery
and aJQueryImpl
.I would consider naming your interface something like
JavaScriptLibrary
and then name your implementing classJQuery
orPrototype
.In Java:
与书面语言相比,大多数命名约定“看起来很奇怪”。但从长远来看,坚持遵守惯例是有回报的。
Most naming conventions "look weird" when compared to written language. But consistently following a convention pays off in the long run.
Ponzao 有一个很好的观点,我倾向于不将类型信息嵌入到类、变量等的名称中。但是,当处理多个文件时,我发现标记接口很有帮助。
我使用了过去非常有用的两种命名约定:
1) m_variableName
m_ 在代码中脱颖而出,标记成员变量。
2) IThisIsAnInterface
对于接口,您可以考虑类似 I_JQuery 的东西,并用 I_ 标记您的接口。
Ponzao has a good point and I tend to not embed type information into the names of classes, variables, etc. However, when dealing with more than a few files I have found marking interfaces to be helpful.
I use two naming conventions that have been very helpful in past:
1) m_variableName
m_ stands out in the code, marking member variables.
2) IThisIsAnInterface
For interfaces you might consider something like I_JQuery with the I_ marking your interface.