If you decide "Program to An Interface" trumps YAGNI and decide to create a supertype where you don't envision anything other than one obvious implementation - is there a convention for naming the obvious concrete type? E.g. this morning I wrote a a class called PlainOldConversionReport and I wonder if that name betrays ignorance of convention. Would there a more normal name, in Object Oriented development generally or .Net or C# specifically, to give to a non specialized subtype of IConversionReport?

  • 4
    Two popular conventions: DefaultConversionReport or ConversionReportImpl. I prefer the former. Dec 30 '11 at 14:46
  • You should program to an interface AND adhere to YAGNI. There is no reason to add superfluous code to an interface. Dec 30 '11 at 16:38
  • @TomSquires: Is it clear from context that by "Program to an interface" I meant use a syntactic feature like abstract class or a keyword "interface"? Is it controversial that some classes clearly should have a formal-at-the-syntax-level interface and some classes clearly shouldn't, and that there is a third class? Are you saying that if I decide to use a syntax-level interface where it's not obviously warranted, I must be introducing superfluous code? Dec 30 '11 at 16:52
  • 1
    "Simple" and "Default" come to mind. I don't like "Impl" because it's not a word, and I strongly prefer code that can be read aloud. Dec 30 '11 at 18:30
  • +1 I like "Simple" most so far for the kind of thing I had in mind. As long as other people use it and readers will know what I mean. I unheart Impl too, but you can read it out loud - you can read "int" and "var" right? Just say "Simple" without the "S" Dec 30 '11 at 18:51

If there is no obvious name for the specialization in the single implementation, my teams have always normally used Impl as a suffix. If there is an obvious name, I would stick with it even if it will be the only implementation.

  • First, most upvoted reply that I can mark as an answer - but thank you all, upvotes all around. Neither "Impl" or "Default" seem logical to me (Impl says too little; Default says too much) but my question was what's the convention. Dec 30 '11 at 17:19

For IConversionReport, I'd simply use ConversionReport. I guess you know this already, but IXXXX and XXXX is a bit of a code smell. I think you should probably think a bit harder to see if there's a better name that gives some hint of what the implementation is (or drop the interface if you're neither doing any composition nor swapping out different implementations).

  • 1
    I know illustrious guys like Bob Martin say "IXXXX" is bad old practice and I see the point but it sure seems entrenched in .Net -- to me it seems like you're communicating something "special" if you have a non "I*" interface -- "I*" seems clearer. As far as dropping the interface, that is probably the most logical course, in my case. It's "YAGNI" vs "Might need it and interfaces are cheap." But it's borderline. In this case and in my opinion. Dec 30 '11 at 16:33
  • 1
    ISomething and Something is a heck of a lot better than Something and SomethingImpl.
    – Kyralessa
    Jul 5 '12 at 1:48
  • 2
    @Kyralessa and MakeMinePanacea - well yes. What I mean is that if you have IReportGenerator and ReportGenerator then it's a bit of a code smell vs IReportGenerator and XMLReportGenerator for example. I agree that Something + SomethingImpl is probably even worse. In .net I'd always stick with 'I' as a prefix for interfaces as it's so idiomatic, whatever the advice is from Uncle Bob.
    – FinnNk
    Jul 6 '12 at 15:19
  • @FinnNk: I see nothing wrong with having interface IFoo and class Foo is fine if Foo would be the normal reasonable choice for code which never uses an IFoo as anything other than an IFoo, and if the only reason for wanting other implementations was that they could provide features not defined within the interface.
    – supercat
    Feb 24 '14 at 2:29
  • After years of C#, I'm working in a Java shop now, and the non-I convention drives me mad. It's extraordinarily handy to look at a thing and know whether it's something I can instantiate in and of itself, or whether I need to look for something that implements it. In Java, classes and interfaces are all mashed together because of the lack of this I convention. This makes reading code harder.
    – Kyralessa
    May 6 '18 at 13:45

I use a prefix of Base, so BaseConversionReport.

I clearly misread the question. My apologies. If there is a simple, bog-standard implementation for the ConversionReport, I'd simply call it ConversionReport or StandardConversionReport and call the SuperType BaseConversionReport (or ConversionReportBase.)

  • In .net 'base' (usually as a suffix) implies that it's a base class/supertype.
    – FinnNk
    Dec 30 '11 at 15:56
  • Really a downvote? The questioner is asking for how to name a Supertype. Base is a perfectly acceptable suffix or prefix for identifying that.
    – Jacob G
    Dec 30 '11 at 16:03
  • @JacobG, actually I was asking how to name the implementing subtype. So I guess someone downvoted for that. Dec 30 '11 at 16:15
  • "Standard" seems more logical to me than any of the others for the type I was thinking of - but I take it from this scientific survey I've just completed that "Impl" is more widely used. Thanks. Dec 30 '11 at 17:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.