开发者

Name Interface conventions when name already start with capitalized letter

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 yo开发者_运维百科u think ?


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 an IJQuery and a JQueryImpl.

I would consider naming your interface something like JavaScriptLibrary and then name your implementing class JQuery or Prototype.

In Java:

public interface JavaScriptLibrary { ... }

public class JQuery implements JavaScriptLibrary { ... }

public class Prototype implements JavaScriptLibrary { ... }


Most naming conventions "look weird" when compared to written language. But consistently following a convention pays off in the long run.


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.

-bn

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜