When I write the application, I use the System.Data interfaces (IDbConnection, IDbCommand, IDataReader, IDbDataParameter, etc.). I do this to reduce vendor dependencies. If I am not doing a simple test application, it just looks like an ethical thing when you consult.
However, it seems that all the code that I see uses the System.Data.SqlClient namespace classes or other provider-specific classes. In magazines and books it is easy to chalk up this influence of Microsoft and their marketing to program only against SQLServer. But this is similar to almost all of the .NET code that I see uses certain SQLServer classes.
I understand that specific classes of providers have more functionality, for example, adding a parameter to the SqlCommand object is one of the methods where adding it to IDbCommand is an annoying 4+ lines of code. But then again; writing a small helper class for these constraints is quite simple.
I also wondered if programming with interfaces when SQLServer is the current target client is over engineering, as it is not required immediately. But I do not think that this is due to the fact that the cost of programming against interfaces is so low that, since reducing dependence on suppliers provides such a huge benefit.
Do you use specific data classes or provider interfaces?
EDIT: To summarize some of the answers below, and think about how I read them.
Possible problems with the use of interfaces for neutrality of suppliers:
- Provider keywords built into your SELECT statements (all my inputs, upd, and del are in procs, so this is not a problem)
- Direct database binding is likely to raise questions.
- If your connection instantiation is centralized, a particular provider class will need to be called anyway.
Positive reasons for using interfaces:
- In my experience, the ability (even if not implemented) to switch to another supplier has always been appreciated by the customer.
- Use interfaces in reusable libraries.
John MacIntyre
source share