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 ?
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 ?
Most naming conventions "look weird" when compared to written language. But consistently following a convention pays off in the long run.
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 { ... }
Depends on the language conventions and yes, C# made interface names prefixed with 'I' because
there is no distinction in syntax between sub-classing a class and implementing an interface.You have to use :
for both the operations,so in order to distinguish between Classes and Interfaces,MS did bring prefix convention.But where as in case of Java there are two keywords extends
and implements
for subclassing and implementing an interface.Then there is no need of prefixing.
I always follow the conventions set by community or language designer unless i am the sole maintainer of my own code which is very unlikely.
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