Friday, May 30, 2008

Programming to Interfaces Buy me Something. For sure

Today I've read a post from Ben Northrop - Does Programming to Interfaces Buy Us Anything?

I really understand, that interfaces hurt sometime. And many of us use because of these "reduced coupling, maintainability and testability" features. But there are numerous examples of interfaces usage, which you can dind useful every day:
1) It is very common to switch from JDBC DAO to a Hibernate DAO and conversely, for performance gains, or ad-hoc SQL. Or, from Hibernate to iBATIS, for reporting methods.
2) Though you can generate proxies for classes, they are not easy to test and debug. Let's take a simple ubiquitous example - transactional facade, defined via Spring's interceptor. When you proxy with CGLIB you can end up with stacktrace without source code line information. And you couldn't step through the code, because "source is not found". This can be an IDE limitation, but with interfaces thing are much better.
3) Mock frameworks are not a panacea. Sometimes you need to create mock yourself.
4) Miss F3 in Eclipse for interfaces? Use Ctrl+T!

I can found more practical examples of interface benefits, but they already buy me a lot during my daily work as a developer

No comments: