tags:

views:

88

answers:

5

Hi StackOverflow!

My question is rather simple and the title states it perfectly: How do you name your "reference" or "basic" implementations of an interface? I saw some naming conventions:

  • FooBarImpl
  • DefaultFooBar
  • BasicFooBar

What do you use? What are the pros and cons? And where do you put those "reference" implementations? Currently i create an .impl package where the implementations go. More complex implementations which may contain multiple classes go into a .impl.complex package, where "complex" is a short name describing the implementation.

Thank you, Malax

+2  A: 

I wonder if your question reflects the customs of a particular language. I write in C#, and I typically don't have "default" implementation. I have an interface, say IDistance, and each implementation has a name that describes its actual purpose / how it is specific, say, EuclidianDistance, ManhattanDistance... In my opinion, "default" is not a property of the implementation itself, but of its context: the application could have a service/method called "GetDefaultDistance", which would be configured to return one of the distance implementations.

Mathias
A: 

I asked a previous question about a "null" implementation and it was identified as the null object pattern - an implementation of an interface that does nothing meaningful. Like Mathias, I'm not too sure what would be considered a "default" implementation that didn't have some kind of name specific to its implementation.

Josh Einstein
A: 

If the interface is a RazmaFrazzer, I'd call the implementation a DefaultRazmaFrazzer.

If you've already got several implementations and you've marked one of them out as a "default" look at all the implementations and look at the differences between them and come up with an adjective that describes the distinguishing feature of the default implementation e.g. SimpleRazmaFrazzer, or if it's a converter, you might have PassThroughDefaultRazmaFrazzer - so you're looking for whatever makes the implementation distinctive.

cartoonfox
+1  A: 

In Java, (whenever suitable) I typically use a nested class called RefImpl. This way for a given interface InterfaceXYZ, the reference implementation is always InterfaceXYZ.RefImpl and there is no need to fumble around making up effectively redundant names.

public interface InterfaceXYZ {

   // interface methods ...

   public static class RefImpl implements InterfaceXYZ {
        // interface method impls.
   }
}

And then have a uniform usage pattern:

// some where else
public void foo () {

    InterfaceXYZ  anXYZ = new InterfaceXYZ.RefImpl();

    ...
}
A: 

The exact convention doesn't metter - be it IService + Service or Service + ServiceImpl. The point is to be consistent throughout the whole project.

Bozho