logo
  • Jobs
  • About Me
  • Contact
  • Home
« Technical Debt
Google Reader »

IList, IComparable, ICaramba!

Posted October 6th, 2005 by Matt Berther

Micah Martin has a post over at Uncle Bob’s that talks about reasons to step away from the I naming convention for interfaces.

For the most part, Ive tried to stick with the framework guidelines as far as this practice goes. However, Micah makes some very compelling arguments as to why this should be avoided. Specifically, the need to change from an interface to an abstract class down the road.

I’m starting to lean towards not naming interfaces with the I convention. Have you made a decision one way or the other on this? If so, which convention are you using and why?

4 Comments

This entry was posted on Thursday, October 6th, 2005 at 3:12 pm and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

David Starr
October 6th, 2005

ILikeIt. If you need to add functionality in an abstract class, have your absract class implement the interface.

Sean Timm
October 6th, 2005

Martin makes the assumption that you own all the code that implements the interface. If you don’t, then changing to an abstract base class is not a good thing at all.

By exposing an “IWhatever” interface that I can implement against, you’re setting up a contract with me that makes certain guarantees…

I know it’s just an interface, so deriving from it is not going to do anything unexpected beyond requiring me to implement those methods (and any code that will be called is my own). Since I know it’s an interface, I can choose to derive from a different abstract base class without fear of this causing me any problems.

Now you may still decide that IWhatever was a big mistake in your next release, so you may deprecate or remove it and provide an alternative “AbstractWhatever” class. I know by the semantics of it what I need to change to make this all work again, and I’m okay with that.

Now this isn’t as important with private interfaces that are only being used with your code (and will only ever be used with your code)…but now you’ve got some inconsistency in how your interfaces are handled, and if you ever *do* need to expose one of those internal ones, you’ll regret not having named it IWhatever from the get-go.

So…three rules:

1. Don’t screw with a public contract. If you must, remove it and provide the new contract.

2. Prefix your interfaces with an “I”. ILikeItToo.

3. Name your abstract classes AbstractWhatever… unless you plan on your abstract classes morphing into concrete implementations. (I assume this is where you might want to argue with me the most…) :)

All that being said, I’ve asked myself these same questions and gone back and forth, so please try and convince me otherwise…

Jed
October 8th, 2005

I agree that we should not change public contracts, but I strongly disagree with naming abstract classes with an Abstract prefix or suffix. This notion of naming classes with Abstract, Concrete, and Factory prefixes or suffixes reminds me too much of using Hungarian notation to work around deficiencies in loosely typed languages. These types of details belong in the XML documentation and in the help files.

Sean Timm
October 11th, 2005

I knew I’d get arguments here… :)

I guess you’re assuming that abstraction is not a contract. When I provide an AbstractWhatever class, I’m making a contract that this class will *never* be a concrete class. I have no intention of ever directly instantiating one of these things, and I’m providing it to support whatever is deriving from it. The name enforces the notion that you shouldn’t be changing the class from abstract… consider deriving your own concrete class from it, instead. It fosters a realization in others that may be working with the code that changing this thing is going to affect more than just itself.

If, in the course of refactoring, you discover that you actually *do* need a concrete instance of this thing you thought was abstract only, then derive from the abstract and start pushing all the logic up into the new concrete Whatever class until you can finally get rid of your AbstractWhatever class.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
-->

flag
Favorite Charity
wounded warrior project
Search
Social
  • mattberther on twitter
  • mattberther on linkedin
Syndication
Archives
  • January 2010
  • September 2009
  • July 2009
  • June 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • September 2008
  • August 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008
  • December 2007
  • November 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007
  • February 2007
  • January 2007
  • December 2006
  • November 2006
  • October 2006
  • September 2006
  • August 2006
  • July 2006
  • June 2006
  • May 2006
  • April 2006
  • March 2006
  • February 2006
  • January 2006
  • December 2005
  • November 2005
  • October 2005
  • September 2005
  • August 2005
  • July 2005
  • June 2005
  • May 2005
  • April 2005
  • March 2005
  • February 2005
  • January 2005
  • December 2004
  • November 2004
  • October 2004
  • September 2004
  • August 2004
  • July 2004
  • June 2004
  • May 2004
  • April 2004
  • March 2004
  • February 2004
  • January 2004
  • December 2003
  • November 2003
  • October 2003
  • September 2003
  • August 2003
  • July 2003
  • June 2003
  • May 2003
  • April 2003
  • March 2003
mattberther.com © 2003 - 2010