Interfaces and Implementations

Consider a Java interface and class: Dog and DefaultDog. Which of these two conventions is best?

Option 1 : Dog

Name the interface Dog and call the implementation something like DefaultDog or DogImpl.

Option 2 : IDog

Name the interface IDog and call the implementation Dog, DefaultDog, or whatever else you can come up with.

The Answer

I prefer option 1 for these reasons:

  • A vast majority of your code will utilize the interface, rather than the implementation. Thus, it’s best to keep the interface name clean, and reserve the weird names for the implementation classes, which you hardly ever see.
  • Prefixing names with “I” feels like Hungarian notation. The name redundantly specifies what the interface keyword already specifies. Should we also adopt notations for things that are static, final, abstract, etc? I think not.
  • Many interfaces will have multiple implementations. Thus, each implementation will need a different name. I see no need to also put some name discriminator on the interface.

Regarding names like “Impl” and “Default”, I prefer to avoid those when possible. For example, ArrayList and LinkedList are far better names than DefaultList or ListImpl.

Win 7 Printing to Airport Printer

We have a combination of Mac and Windows machines in our house, and I was unable to get a new Windows 7 64-bit machine to print. The printer is shared using an Airport Extreme Base Station.

I downloaded Bonjour for Windows and it immediately detected the printer. Everything seemed OK, but printing always failed.

This led to many hours of failed searching and troubleshooting. I found many people have the same problem, and many solutions being offered. Nothing worked, until I noticed the “here” link:

64-bit Bonjour

With those highlighted circles, it seems painfully obvious. But the “download” button is more prominent, so I didn’t read the text. Based on the number of people I encountered having the exact same problem, I must not be the only one to miss this.

The real kicker is the fact that 32-bit Bonjour fails to warn you if you install it on a 64-bit PC. It happily finds the printer, leading to a false sense of success.

One last tip — if Bonjour can’t find the driver, first plug the printer directly into your PC. Windows should be able to download the right driver.