Java interface and implementation naming (or “I” or “Impl”)

How do I name my interfaces and the classes that implement my interfaces? Through much research on the internet and my own gut feelings, this is what I reckon:

I never prefix my interfaces with “I”. The value of coding to interfaces is that you can swap out the implementation with minimal hassle. It means that instead of using implementation specific class names in your code, you use interface names instead – right? So, if I’m going to be using interface names everywhere, I don’t want to have to prefix everything with “I”. Coding to interfaces is a best practice, so I don’t need to explicitly state that I am doing it…It should just happen – which makes the “I” prefix redundant.

Furthermore, the “Impl” suffix is also redundant. Yes, indeed, your dilemma isn’t as simple as picking between the two. Firstly, “Impl” doesn’t translate. “Impl” in other languages has no meaning, and yes I’m talking about Polish and Scala. In Polish (according to Google translate), “implementation” is “realizacja” and in Scala, there are no interfaces. The closest thing Scala has to interfaces is traits, which can contain implementation specific code. So really, everything is Scala is an implementation, so why you use “Impl” suffix?

Secondly “Impl” is restrictive. What happens when you want to add another implementation of Foo? You gonna call it “FooImplImpl”? “AnotherFooImpl”? “FooImpl2″? I didn’t think so. Perhaps you were going to just call it “FooImpl” and put it in a different package…

Thirdly “Impl” doesn’t convey any meaning about what the implementation is. You wouldn’t create an “AnimalImpl” would you? You’d create a “Lion” or an “Elephant”. There is almost always something that distinguishes your implementation that you can use in the class name. Even if it is a long name, it doesn’t matter – you’re coding to interfaces (remember?), so you’re rarely going to see that class name.

Lastly, and probably most importantly – you still can’t think of a name? You don’t need an interface. If you really can’t think of a name, your class must be generic enough to not need an interface and you’re probably not going to have any other implementations. Your class methods become the interface contract, and that is that.

3,247 thoughts on “Java interface and implementation naming (or “I” or “Impl”)

  1. social tournaments app Najlepsze nowe kasyna online niemam czy nie mam

  2. best online casino for blackjack Darmowe spiny bez depozytu 2026 nicki na steam

  3. kod promocyjny na total casino 100zl bez depozytu za rejestracje mr bet opinie

  4. ile idzie przelew z total casino Najlepsze nowe kasyna online gaminator 777 gry kasyno sloty darmowe automaty

  5. polska kasyno onlineile cristiano ronaldo strzeliЕ‚ goli п»їaktualne bonusy bez depozytu polska ruletka online

  6. kasyno bonus pieniezny bez depozytunational casino no deposit bonus najlepsze kasyno na telefon kasyno internetowe bez rejestracji

  7. legalny polski bukmachergry za pieniadze prawdziwe kasyno online szybkie wypЕ‚aty automaty do gier

  8. betsson bonus za rejestracjД™online automaty synot kasyno online opinie luty Е›wiД™ta nietypowe

  9. lemon casino free spins no depositmilky way casino bonus bez depozytu kasyno online blik mr bet 70 za rejestracjД™ bez depozytu

  10. live blackjack onlinedarmowe spiny book of dead п»їaktualne bonusy bez depozytu betonred bonus code

  11. betonred bonus codegra automaty online kasyno online szybkie wypЕ‚aty kasyno internetowe z bonusem na start

  12. legalne kasyno online polskakasyno online wpЕ‚ata depozytu sms 5zl najlepsze kasyno na telefon game blackjack online

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>