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.

8,992 thoughts on “Java interface and implementation naming (or “I” or “Impl”)

  1. аренда автокрана екб автокраны аренда спецтехники

  2. king kong casino ruleta online zadarmo automaty bonus bez vkladu

  3. Купить Кокаин Бошки Марихуану Мефедрон Гашиш москва

  4. online casino euro automaty online realne peniaze vyherne automaty zadarmo

  5. casino 1 € bonus Zahraničné online casino bonus bez vkladu smart live gaming casino

  6. Купить Кокаин Бошки Марихуану Мефедрон Где можно купить мефедрон

  7. automaty kajot hry zdarma online casino bonus bez vkladu video blackjack online

  8. What online casinos give you free play ZahraniДЌnГ© online casino bonus bez vkladu platba cez slovak telekom online automaty

  9. Купить Кокаин Бошки Марихуану Мефедрон Гашиш москва

  10. mrbet no deposit bonus OvocnГ© hracie automaty zadarmo hracie automaty zdarma poker

  11. hrat automaty zdarma 3 valcove casino bonus bez vkladu europa casino bonus no deposit

  12. Купить Кокаин Бошки Марихуану Мефедрон Телеграм мефедрон

  13. fortuna pЕ™ihlГЎЕЎenГ­ online ZahraniДЌnГ© online casino bonus bez vkladu online casino narodeninovy bonus

  14. automati hri zdarma kajot ruleta online zadarmo casino bonus pri registrГЎcii

  15. Купить Кокаин Бошки Марихуану Мефедрон Где можно купить марихуану

  16. vyherne automaty online casino vklad mobilom hry automaty zdarma sizzling

  17. Купить Кокаин Бошки Марихуану Мефедрон Где купить альфа пвп

  18. многостраничный сайт на тильде сайт на тильде для бизнеса

  19. sizzling hot automaty zdarma KasГ­na s minimГЎlnym vkladom 20 eur trojvalcove automaty zdarma

  20. Дизельное топливо https://neftegazlogistika.ru оптом с доставкой по Москве и Московской области для регулярных и разовых поставок. Летнее межсезонное и зимнее ДТ разные объемы заказа доставка на объект и возможность заключения договора для постоянного сотрудничества.

  21. Независимый рейтинг https://рейтинг-сюрвейерских-компаний.рф сюрвейерских компаний России поможет сравнить организации которые занимаются инспекцией грузов экспертизой контролем качества и количества товаров. Оцените опыт специализацию географию работы репутацию и спектр услуг ведущих участников рынка.

  22. 21 3 blackjack online free п»їnajlepЕЎie online kasГ­no vlt automaty online

  23. Купить Кокаин Бошки Марихуану Мефедрон Где купить героин

  24. casino bonus bez vkladu za registrГЎciu casino dobitie cez sms automaty zdarma szili hot

  25. automaty hry zdarma lucky KasГ­na s minimГЎlnym vkladom 20 eur mГЎte kasГ­no v turecku

  26. Купить Кокаин Бошки Марихуану Мефедрон Телеграм купить меф

  27. Рейтинг строительных компаний https://рейтинг-строительных-компаний.рф России: обзор крупнейших участников строительного рынка их проектов и показателей деятельности. Узнайте какие компании лидируют по объему текущего строительства регионам присутствия и количеству возводимых объектов.

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>