This is beginning to look like the "thread that never ends"…
Robert posted a few additional thoughts that I’d like to comment on:
Cedric, you said you wanted to distinguish between needing to use ‘new’
vs a factory. Why bother? Simply use a factory _all the time_ for your own
I like factories a lot, but using them all the time is a bit extreme in my
opinion. Constructors have a lot of shortcomings (name that changes all
the time, can’t use polymorphism, etc…) but they are a fairly convenient
construct and I think banning them from everywhere in your code base except for
a small set of factory methods might be a bit overkill.
BTW, I said that adding numbers to an interface was an admission you made
a mistake – namely, that you forgot something.
That’s a bit harsh. No matter how much thought you have put into an
interface, you can’t really anticipate all the crazy ways future users will want
to use it for. I would certainly not call this a mistake, maybe just a
lack of foresight, but it certainly doesn’t reflect badly on the author of the
interface in my eyes.
Another comment about numbered interfaces:
Anybody who first sits down with various COM API’s and encounters all the
different numbered interfaces and has no idea what the difference is between
them can attest to this.
Actually, the numbers serve a very useful purpose: the higher the
number, the more sophisticated the interface is. When you are wondering
which one to implement, the numbered interfaces give you a good way to figure
out how much functionalities you want to implement and if the one without a
number is good enough for you, it will also be the one with the least methods,
so the easiest to implement. When you don’t use numbers, comparing the
richness of interfaces that extend each other is not as obvious.
In another comment, Alex Blewitt made another excellent point:
One advantage that a prefix has over a suffix is nothing to do with
JavaDoc; it allows you to get a list of all interfaces by typing
I+ctrl+space (or whatever your favourite IDE uses).
This made me realize that I use this a lot, along with other conventions that
use prefixes instead of suffixes:
- get/set for getters (obvious). It makes it
straightforward to see what properties you can query from an object (type
- A leading underscore (e.g. _name) for fields.
Overall, I feel that if you are using an IDE, conventions that use prefixes
instead of suffixes will make your life easier, but at this point, I’m ready to
concede that it’s really nitpicking. At least, most of the people who
commented seem to agree on the fact that differentiating interfaces from
concrete classes with syntactic conventions is useful, and the rest is details.
So just pick a convention and stick with it.