Link Details

Link 32801 thumbnail
User 207620 avatar

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.
  • 58
  • 11
  • 9922
  • 22

Comments

Add your comment
User 77421 avatar

rd112681 replied ago:

0 votes Vote down Vote up Reply

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?

User 179375 avatar

Ricky Clarkson replied ago:

2 votes Vote down Vote up Reply

Please don't inherit from my neatly named Foo, if 'implements Foo' fails. It probably just means I omitted the word 'final' somewhere.

User 205849 avatar

nothingHappens replied ago:

0 votes Vote down Vote up Reply

You're probably just overusing inheritance.

User 205849 avatar

nothingHappens replied ago:

4 votes Vote down Vote up Reply

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

User 161152 avatar

matthew cox replied ago:

2 votes Vote down Vote up Reply

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

User 188795 avatar

villane replied ago:

0 votes Vote down Vote up Reply

But IRobot and IAnticorruption sound so cool :)

User 211189 avatar

rasman replied ago:

0 votes Vote down Vote up Reply

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

User 161152 avatar

matthew cox replied ago:

2 votes Vote down Vote up Reply

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

User 225162 avatar

herval replied ago:

3 votes Vote down Vote up Reply

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

User 210077 avatar

marcelocamanho replied ago:

1 votes Vote down Vote up Reply

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.

User 205849 avatar

nothingHappens replied ago:

0 votes Vote down Vote up Reply

ICanHasBusinessTerms?

User 235652 avatar

gkeim replied ago:

1 votes Vote down Vote up Reply

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

User 77421 avatar

rd112681 replied ago:

1 votes Vote down Vote up Reply

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

User 107114 avatar

daniel replied ago:

2 votes Vote down Vote up Reply

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.

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.

Apache Hadoop
Written by: Piotr Krewski
Featured Refcardz: Top Refcardz:
  1. Play
  2. Akka
  3. Design Patterns
  4. OO JS
  5. Cont. Delivery
  1. Play
  2. Java Performance
  3. Akka
  4. REST
  5. Java