Hacker News new | past | comments | ask | show | jobs | submit login

Both are bad:

If you have Thing as the Interface and ThingImpl as the class you should probably delete the interface and rename ThingImpl to just Thing.

If you really really know multiple implementations are coming down the road you can name the class DescriptionClass (like ArrayList and LinkedList), but generally these days I'll just cross that bridge when I get there. (Always be careful when working on external interfaces though.)

Historical note: In ancient (in a web perspective) Java enterprise edition (not to be confused with modern Java EE) this style was encouraged and even enforced. Today it is widely considered an antipattern. Last time I remember a project where this was how it was supposed to be done was probably back in 2008 in a Spring/JSF project. Both Spring and JSF have changed a lot since then.




But you know that there will be multiple implementations for every interface. At least, after IThing and Thing you will have MockThing


First:

Forget I<Whatever>. It breaks sorting and it is allows people to avoid thinking if the interface is necessary or not.

Second:

I'm not one of the hardliners wrt avoiding mocking, but if every class needs to have a corresponding mock then I'd suggest taking a step back because that shouldn't be necessary, and often in such cases I think one will also find lots of low value or even no-value tests.

I'll not judge you based on a comment on an internet forum, but I think the above is a good heuristic.

(With TypeScript and Java closures or anonymous types is also an option and something exist in C# as well.)


> Forget I<Whatever>. It breaks sorting and it is allows people to avoid thinking if the interface is necessary or not.

100%. Any "structure definition" should be assumed to be an interface, and any explicit separation of definition and implmentation should be deferred until multiple variants are required. My Java projects and files were corked up with Ifiles that only ever had a single implementation.

Caveat: I've only worked on internal projects, explicit interfaces are much more useful for something widely shared. Don't use the I<Class> convention though.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: