Jarrod Roberson's avatar image.

Opinionated Software Craftsman

My name is Jarrod Roberson, and I have been on a self taught software development journey for the last 30 years

Anonymous profile image
  • How to avoid the "ITruck"/"TruckImpl" tautology while trying to keep clean the dependencies of my API in Java?

    I really enjoyed following your answer and discussions here http://stackoverflow.com/questions/2814805/java-interfaces-implementation-naming-convention , but IMO there is one unsolved puzzle piece wrt that question, and I truly want to know you opinion about it.

    What if I want to expose an API to the "outer world", and ship this API as e.g. a separate maven artifact: I don't want this API to have any implementation-specific dependencies, but I still have only a single implementation of the API? I don't see how to avoid some sort of "tautology" completely in this case... i.e. either Truck is a class and my api package will have dependencies on e.g. MaxTheDriver, or I have to split it into Interface Truck and .. well.. class TruckImpl that actually depends on MaxTheDriver :)

    p.s. I know this belongs rather to the SO site, but I cannot comment there and I really wanted to know your opinion. Sorry if it's too offtopic for this place..

    Jarrod Roberson's avatar image.

    This is very simple, look at how SLF4J handles it. There is the public interface in one .jar and implementations of those interfaces in others.

    If you really are stuck with the only thing you can think of naming something is to prefix it with Impl, still reeks of lack of imagination or you should put it in its own package.

    That is how JDBC driver and SLF4J implementations are packaged, in their own packages.