Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
4  
Two popular conventions: DefaultConversionReport or ConversionReportImpl. I prefer the former. –  Steve Jackson 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. –  Tom Squires 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? –  MakeMinePanacea 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. –  kevin cline 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" –  MakeMinePanacea Dec 30 '11 at 18:51
show 1 more comment

3 Answers

up vote 1 down vote accepted

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.

share|improve this answer
    
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. –  MakeMinePanacea Dec 30 '11 at 17:19
add comment

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).

share|improve this answer
    
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. –  MakeMinePanacea Dec 30 '11 at 16:33
    
ISomething and Something is a heck of a lot better than Something and SomethingImpl. –  Kyralessa Jul 5 '12 at 1:48
    
@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 at 2:29
add comment

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.)

share|improve this answer
    
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. –  MakeMinePanacea 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. –  MakeMinePanacea Dec 30 '11 at 17:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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