Published: Jul 31 2007 / 11:19
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?
Please don't inherit from my neatly named Foo, if 'implements Foo' fails. It probably just means I omitted the word 'final' somewhere.
You're probably just overusing inheritance.
Voted up just because I happen to find the IFoo naming convention really annoying :D
I don't mind the 'I' part so much, but please stop naming examples 'Foo'
But IRobot and IAnticorruption sound so cool :)
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? :-)
You'd use IIPod and IIPHone in those cases. Duh!
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
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.
Even though I disagree with Taylor, I voted up because I love a mud raker!
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
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.
Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.