By tgautier
via javathink.blogspot.com
Published: Jul 31 2007 / 11:19
Leave the IBizness to Senor Jobs & Co. Writing interfaces named IFoo subtly breaks the notion of an interface. Read why it doesn't belong in your code.
Comments
rd112681 replied ago:
See, for example, Java Design, by Peter Coad and Mark Mayfield. About page 85.
Say I want to inherit from your neatly named Foo.
For this I need to know (in Java) whether or not it's an interface. (If it IS, then an existing class/interface can implement/extend it. If not, then I have to just subclass it.)
Wouldn't it be a fine thing if I could tell this just from the name?
Ricky Clarkson replied ago:
Please don't inherit from my neatly named Foo, if 'implements Foo' fails. It probably just means I omitted the word 'final' somewhere.
nothingHappens replied ago:
You're probably just overusing inheritance.
nothingHappens replied ago:
Voted up just because I happen to find the IFoo naming convention really annoying :D
matthew cox replied ago:
I don't mind the 'I' part so much, but please stop naming examples 'Foo'
villane replied ago:
But IRobot and IAnticorruption sound so cool :)
rasman replied ago:
Isn't the whole point that the programmer using your API shouldn't have to care if the Foo that's returned is a class or an interface? Methods can be called on either. It SHOULD be transparent. That's my opinion anyway.
What do you do when you're writing java classes for Apple products? Is IPhone a class or an interface? What about IPod? IRack? :-)
matthew cox replied ago:
You'd use IIPod and IIPHone in those cases. Duh!
herval replied ago:
here at work we have some very neat interface names
there's an old IHasID interface, used for objects that have an ID in a bizarre object-oriented db. Then the naming caught, and all sorts of weird names appeared: IHasVolumes, IHasBusinessTerms.
Until some guy decided that IHas is not english at all and started naming his interfaces IHave. And now, besides the IHasIDs and IHasStuff, we have a bunch of IHaves: IHaveTax, IHaveDataArray. Not to mention the IMayBeBillable, IMayBeReportable...
True story... :-s
marcelocamanho replied ago:
sadly i have to validate this story. i work on the same place.
im not too fond of having to be forced to use interfaces sometimes, but i agree that on most cases it is a good design to use them. and this naming convention of using an I really sucks. It should not matter to the code whether is an interface, class or banana.
nothingHappens replied ago:
ICanHasBusinessTerms?
gkeim replied ago:
Even though I disagree with Taylor, I voted up because I love a mud raker!
rd112681 replied ago:
If Foo is designed to be inherited, then you DO care if it's an interface or not.
If the name of the class tells you this, then so much the better.
Foo: concrete class
AbstractFoo: abstract class
IFoo: interface
daniel replied ago:
Overusing the convention is a bad idea. However, for certain things the I* naming style *is* a good thing. For example, if you have a class "DatabaseHander", but (for whatever reason) you had to abstract most of the class signature into a superinterface, naming that interface "IDatabaseHandler" actually makes some sense.
Voters For This Link (58)
Voters Against This Link (11)