Answer the question
In order to leave comments, you need to log in
Interface declaration rules. "I" or "!I"?
Hello.
Who can adequately explain why it is worth declaring interfaces with the letter "I":
interface IDisposable
{
}
interface Disposable {
}
Answer the question
In order to leave comments, you need to log in
There is no "official" strict convention on this matter. As RGV has already pointed out , which convention to use is a personal matter for the team/company/tech director.
I myself once came to Java from Pascal and .NET, and I also adhere to the notation with I, because this allows you to visually distinguish the interface from the class in the code. Just for example:
...
IProducer simpleProducer = new Producer();
IProducer sofisticatedProducer = new SpecialProducer();
...
public void produceSomething(IProducer producer);
In C#:
1. Microsoft's naming convention for C#, which everyone uses
2. To distinguish from classes
How it's done in Java - Java experts know and I think they have reasons to do what they do (including, I don't know if they are right specifically your javascripts or not), however there is no reason for javascripts to follow the naming conventions from c# and vice versa.
Somehow everything is unconscious... There is a persistent rejection of Java-style, but "why" - not a single thought?! Javers mixed you with shit, too, you see, also without any justification. Let's do it yourself - why do you need this letter yourself? How does she help?
From experience: java does not use elements of Hungarian notation , including the interface name does not have the "I" prefix. When implementing an interface, classes are sometimes given the "Impl" suffix (but not always; most likely only when the only purpose of the class is to implement the interface).
How to justify, I do not know, most likely, it happened historically. There are some general coding conventions from Sun, but they are used as guidelines rather than hard and fast rules. Well, all normal IDEs (at least for java) are able to show the type of any identifier, so it is redundant to indicate this in the name.
It's just a coding style. The ideology that the team adheres to. No more.
In our team, the prefix "I" is not used. Everyone is right in saying that this agreement has pluses and minuses and is generally a matter of personal taste. There are many very good projects where I is used and where I is not used. The main thing is that it does not turn into a religion. If you are being treated like crap at work, consider whether you need such a job :-)
Well, there is a clear difference. For me, for example, the authority of the Java api. And there prefixes are not used.
Yes, and I myself believe that visually distinguishing interfaces from classes in java makes no sense and is even harmful. Sometimes, of course, I call *Impl names, but this is from laziness. The title should clearly describe the implementation.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question