Why do default implementations have such bad names?

Small rant about class names in Java, or more specifically classes who are the sole implementation of a particular interface. You go to the effort of coming up with a good name for your interface, e.g. IndexSearcher, but then the class name is enevitably one of:

  • SimpleIndexSearcher
  • IndexSearcherImpl

I’m guilty of this. There must be a better way to name our classes!?!

Don’t forget the other pattern, if IndexSearcher is your class, then IIndexSearcher is your interface. I hate that one too. :)

Spread the word: Technorati related  |  Technorati related  |  del.icio.us bookmark it!  |  submit Why do default implementations have such bad names? digg.com digg it!  |  reddit reddit!

5 Responses to “Why do default implementations have such bad names?”

  1. JD says:

    Hungarian notation has fallen out of favour for a reason. .NET appears to have brought back the I prefx for interfaces and there is no need for it.

  2. James says:

    I don’t see what’s wrong with those two names… Why would you have something intentionally as the “sole implementation of a particular interface” with no intention of adding further implementations? Which means either of the two names suggested might be OK (although ‘SimpleIndexSearcher’ is more descriptive than the ambiguous ‘IndexSearcherImpl’).

    Or you could have done with it and name classes after random European cities :-)

  3. Miles says:

    I just feel it’s a code smell, normally indicating that there was no reason for the interface and implementation to be split in the first place.

  4. JD says:

    What about places where you want to have alternative implementations, but only provide one. Two examples spring to mind. DateFormat/SimpleDateFormat and Calendar/GregorianCalendar. Obviously if there will only be one implementation then you’ve designed it badly.

  5. Miles says:

    If there are other possible implementations, e.g. Calendar/GreogorianCalendar, then the split is justified. But creating an interface with just one implementation can lead to implementation details in the interface. e.g. In the Calendar interface you have constants representing months that belong to the GregorianCalendar, but Lunar calendars have 13 months so you get the silly UNIDECEMBER constant. IBM’s icu4j project reimplemented Calendar to better support subclassing for different calendar types.

    I don’t like the name SimpleDateFormat because the class is anything but simple. It’s a comprehensive implementation of a date formatting language, and its name should reflect that.

Leave a Reply

Line and paragraph breaks automatic.
XHTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>