Link Details

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.

Posted by tgautier  |   Jul 31 2007 / 11:19

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Comments

User 77421 avatar

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?

Reply 0 votes
User 179375 avatar

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.

Reply 2 votes
User 205849 avatar

nothingHappens replied ago:

You're probably just overusing inheritance.

Reply 0 votes
User 205849 avatar

nothingHappens replied ago:

Voted up just because I happen to find the IFoo naming convention really annoying :D

Reply 4 votes
User 161152 avatar

matthew cox replied ago:

I don't mind the 'I' part so much, but please stop naming examples 'Foo'

Reply 2 votes
User 188795 avatar

villane replied ago:

But IRobot and IAnticorruption sound so cool :)

Reply 0 votes
User 211189 avatar

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? :-)

Reply 0 votes
User 161152 avatar

matthew cox replied ago:

You'd use IIPod and IIPHone in those cases. Duh!

Reply 2 votes
User 225162 avatar

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

Reply 3 votes
User 210077 avatar

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.

Reply 1 votes
User 205849 avatar

nothingHappens replied ago:

ICanHasBusinessTerms?

Reply 0 votes
User 235652 avatar

gkeim replied ago:

Even though I disagree with Taylor, I voted up because I love a mud raker!

Reply 1 votes
User 77421 avatar

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

Reply 1 votes
User 107114 avatar

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.

Reply 2 votes

Recommended Links

Scala
Written by: Ryan Knight
Featured Refcardz: Top Refcardz:
  1. Apache Hadoop
  2. Play
  3. Akka
  4. Debugging JavaScript
  5. Design Patterns
  1. Apache Hadoop
  2. REST
  3. Java
  4. Git
  5. Java Performance
Connect with DZone