Click here to Skip to main content
12,689,210 members (30,857 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked

Java: What’s up with “Impl” in Class Names?

, 30 Dec 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
Java: What's up with "Impl" in class names?

What to Name It?

This is a constant question we are faced with in daily life. We want to come up with perfect names for our babies. We want to name our animals (pets) and they seem to be happy to have a name! And it seems to be a big thing! Otherwise, we wouldn’t have naming ceremonies like these. We try to name (rename) our buildings (otherwise what would you call Empire State Building?), streets, cities and countries. (Myanmar or Mumbai is yesterday’s story. Mexico wants to rename themselves as Mexico! See here.) And naming is not an easy thing to do. A world recognized music composer in India, Illayaraja, called his symphonic music album “How to Name it” for lack of a better name.

What’s That Got To Do With This?

Java developers (or any developer for that matter) are merely imitating the real world and they too have to face such challenges while naming their programs, classes and objects. We don’t want to name (can’t) two entities the same name. That would cause confusion (Name Collision). To avoid this, we use packages, name spaces, domain, etc.

Each “object” tends to have 2 forms in Java world (or .NET, C++, etc.) – the class and its interface! An interface is a class’s “public profile” – much like public profile we have in linked-in, what we want other classes to know about this class.

We could say the interface is not unlike a business card or a cover letter we send with our resume when we apply for a job. Cover letter contains exact amount of information that may be of interest to the other party while the resume may have lot more inner details. Now they both are about you, but not the same.

So, What’s Up with “Impl”?

So, if you are a developer, what would you call the interface and implementation for an object that models a real car?

OO interface names

OO interface names

This is not as simple as it seems. There are at least 2 camps. One camp, the Microsoft based camp calls the (implementation) classes by just the name and prefixes their interfaces with “I”. To them, the Implementation is the real object and interface is its business card. The other camp (seemingly started by IBM) uses the plain name for interfaces and the (implementation) classes are named with a suffix “Impl” for Implementation. Here the interface represents the abstracted real word object and the Implementation class merely has extra (inner) details that doesn’t concern outsiders (other classes). The Java world mostly follows the “Impl” convention.

So there you have it, when you see Java classes named with “Impl” at the end, you know why. End of story, right? No, not really. Object Oriented pundits and purists don’t agree. Here is a nice post where the author disagrees with “Impl” usage. And here is another perspective to it. And it’s an ongoing debate. Don’t believe me? See here, here, here.

So Which Way To Go?

Naming your class can be a personal choice, but most of us write programs that will be shared with others in the community. That’s why conventions and best practices exist. If you are working on a project, set up and follow standards appropriate to your shop.

In some cases, you may not be able to change the “I” or “Impl” in names. Many programs may have some type of interface (protocol) like CORBA, COM, Web Services. In these cases, they generate code (Stubs, Skeletons, etc.) that you have to base your own code on. Document these and stick to those conventions to avoid any surprises.

Personally, I am OK with using Impl suffix. I work with EAServer which runs both Powerbuilder and Java objects. These objects “talk” to each other using CORBA IIOP. Both Powerbuilder and EAServer tools generate CORBA IDL files which in turn are used to generate stubs and skeletons in Java (or C++). Developers then write Implementation classes for the interfaces generated. The class files generated and the impl classes may end up in the same Classpath and to avoid Name Collision, we have to name implementation classes differently and the convention is to use Impl suffix. This is a convention I am sticking with in my current project.

Reference Links

A note about my “cheesy” cartoon there. While searching for something relevant, I found Toondoo where you can make your own cartoon. You can start with a free account. I also use openclipart for some of the pictures in my other posts.

Filed under: CodeProject, Java
Tagged: Coding Standards, Java, OO


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Sam Varadarajan
Software Developer (Senior) City of Los Angeles
United States United States
Originally a Physics major, fell in love with Microprocessors and switched to Computer Science 20+ years ago. Since then, dabbled in various languages including, PowerBuilder, Oracle, Java, C, C++, Perl, Python etc. Constantly striving for quality and performance too.

I try to help fellow developers with technology as a way of "giving back to the community". Blogging became a natural extension of that effort. Still learning to perfect that art. If one new programmer out there benefits from this blog, my time and effort are fully worth it.

The underlying theme in my blogs is power and beauty of programming (and technology in general). A well written program gives me the sense of awe you get when you look at a man made wonder like Angkor Wat. You experience poetry, art, mystique, power all at once. A program and the troubleshooting that ensues also gives you a feeling you get while reading a mystery novel!

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170113.4 | Last Updated 31 Dec 2013
Article Copyright 2013 by Sam Varadarajan
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid