An answer to such a question can only reflect the tastes of the person who answers... So these are my tastes:
- I hate the initial
I
. It brings nothing of value to the picture. It reminds me of the Hungarian notation where float variables were to be suffixed with _f
or the like. No.
- The
Impl
suffix is good enough. But on the other hand, it sounds weird.
I'd suggest two alternate proposals for a given interface Foo
:
- create a single implementation but not with the
Impl
suffix; find a more "appealing" name. For instance, TheOnlyOneFoo
;
- create a factory with an appended
s
: Foos
. Then, a Foo
instance would be a Foos.newInstance(whatever, args)
.
I prefer the second solution, for two reasons:
- it can hide the fact that the real implementation has an ugly name;
- it can be extended easily when you realize one day that "no, after all, there is more than one implementation for that": just add another static factory method; and if the only existing method in existence sounds too generic, you can just mark it as
@Deprecated
.
It could even be used in a manner so that all Foo
implementations are package local, or even private to the factory. But stack traces would look worse...
No real solution there ;)
edit: as for mocking:
- I'd recommend mockito. Really. It is very easy to use, and very powerful.
- If those are "one-implementation classes" you are dealing with, maybe there is a better alternative in the JDK itself? What is it that you want to do exactly? The JDK has hidden treasures...
And as a final note... Have you considered the builder pattern?