JAVA : How to name interface and implementor
1 min readNov 4, 2016
So in my new project, every day I had question about naming things.
Here how I name my interfaces and implementor.
Interfaces :
- Name your
Interface
what it is.Truck
. NotITruck
because it isn't anITruck
it is aTruck
. - The prefix hurts readability.
- Don’t forget your interface is a type, so think about people who use this type, they don’t care to know if it is an
Interface
or anObject
- You will never called an Object
TruckClass
because it is a class ? - All modern Java IDE’s mark Interfaces and Implementations and what not without this silly notation.
- Using interfaces in clients is the standard best way to program, so interfaces names should be as short and pleasant as possible. Implementing classes should be uglier to discourage their use.
Implementor :
- A good way to name implementor is to put the name of the implemention + the name of the Interface. So if we have a red truck our implementation should be
RedTruck
- The
Impl
suffix is just more noise as well. - Look to the Java standard library itself. Do you see
IList
,ArrayListImpl
,LinkedListImpl
- So when you have a situation where you have an
Interface
and a singleImplementation
that is not uniquely specialized from theInterface
you probably don't need theInterface
.