Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I name an interface when the base word starts with an I?

I want to create an interface for "Items". Typicaly I would name an interface by adding and "I" prefix to a base word. But in this case my base word already starts with an I. Here are a couple ideas I've had

  • IItem: Two I's
  • Iitem : Vary the case
  • ItemInterface: Skip the I prefix and write out Interface

What looks the best? Has anyone else run into this problem. If so what did you do?

like image 240
Eric Anastas Avatar asked Aug 26 '10 05:08

Eric Anastas


People also ask

How should you name interfaces?

Interface names should be capitalized like class names. Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized. Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter.

Should interface name start with I in Java?

There are two main naming conventions for interfaces in Java: no prefix or suffix for interfaces, ~Impl suffix for implementations, ~I prefix for interfaces.

Should all interfaces start with I?

The "I" in front of interfaces is another backwards convention. When you are passed a reference to an object, you should expect it to be an interface. Interfaces should be the default; so there is no point in doing something extra, like using an I prefix, to announce that you are doing what everyone expects you to do.

How do you name interfaces and implementations?

The name of the interface should describe the abstract concept the interface represents. Any implementation class should have some sort of specific traits that can be used to give it a more specific name.


2 Answers

Although hard to read, IItem would be in line with some existing "II" interfaces:

  • IItem in Windows Mobile 6.5
  • IImplicitResourceProvider
  • IISAPIRuntime
like image 106
p.campbell Avatar answered Sep 21 '22 14:09

p.campbell


Simply IItem. There is no need for an exception.

Interfaces start with two upper case letters (I[A-Z]), which identify them as an interface. So Item is not an interface, but IItem is.

like image 24
Stefan Steinegger Avatar answered Sep 22 '22 14:09

Stefan Steinegger