views:

50

answers:

2

I have my thoughts about this matter but it seems that a lot of libraries and products let third party libs bleed into the API. Logging is a perfect example of this. Nearly everything exposes the need for you to configure that logging API rather than using a provider interface that you can implement and give to the lib.

Is aiming to wrap and hide all libs asking too much ? Is it worth the trouble ?

A: 

I think a lot of it depends on what you are doing. Given the example you are talking about, I think it would be an incredible waste of time and would give the end consumers a less robust package if you completely hide the Third Party API.

For example if you are using Log4Net and hide all configuration aspects, you limit the flexibility to only the items that you integrate/expose. Now, on the flip side, there are times and places where that IS what you want to do.

So I guess the long and short of it is ONLY if there is a TRUE business need to do so. At least that is my $0.02.

Mitchel Sellers
The difference is, that changing config is local - it only affects a few files. If there ever comes the need to switch away from o upgrade to a incompatible log4net, half your code base is immediately wrong and broken. This has happened in the java world w/ log4j when one major class was deprecated in favour or a new equivalent.
mP
+1  A: 

Not only is it not worth the trouble to wrap and hide everything about the libraries, it's often counterproductive.

For example, we have a library that implements a specific HTTP protocol named OAI-PMH. This library is implemented on top of Apache HttpClient 4.0, which has a rich set of configuration parameters. Rather than make up our own configuration parameters that wrap the HttpClient ones, we just expose the Apache library's configuration interface with our own factories and constructors.

If we had tried to wrap all of the Apache parameters, it would have taken months. If we had decided on behalf of our library's users which parameters were important, and only wrapped those, we would have limited what they could do with our library.

Steven Huwig
And what happens when theres a rewrite of HttpClient ? Wrapping always provides the opportunity for you to translate x into y which means you might be able to possibly solve a problem w/out needing your customers to intervene.
mP
Just because there is an HttpClient 5.x doesn't mean that HttpClient 4.x will suddenly stop working. If you have such a tenuous or combative relationship with your third-party library providers, you're better off switching providers or writing your own. Your above "justification" works just as well when applied to the class libraries provided with the runtime. Do you wrap your java.lang.Strings too?
Steven Huwig
Didn't they rewrite HttpClient 4 which is not backcompat with 3 ?One can't compare a value type like String with a service like HttpClient and it's intfs. One is a value type which is almost always a class and the other hidden behind an intf.So what happens when u need to upgrade HttpC ? What happens when it's dependencies like CLogging get in the way ?
mP
HttpClient 3 and 4 can coexist in the same classloader. Even if they couldn't, that's why we have different classloaders and things like OSGI.If we want to use HttpClient 5.x, then we will bump our library up a major revision too.
Steven Huwig
I cant comment about the diffs between hc3 and hc4, but obviously there must have been some improvements. Eitherway your clients are stuck w/ hc3 until some work on btoh sides is done to upgrade to hc4.
mP