tags:

views:

74

answers:

3

I am doing a thin wrapper over a third-party framework, i am thinking following options:

  1. completely wrap the framework, so that the client of the wrapper will not notice the wrapped framework. if so, it means i have to wrap some classes from the framework. this way no dependency between the wrapper's client and the wrapped framework.

  2. expose some classes from the framework to the wrapper's client, it means the client is required to reference the wrapped framework.

what's your opinion?

+1  A: 

I'd say that if the purpose of the wrapper is to make the client application independent of the third-party framework, then the wrapper should include all the aspects of the framework that the client application will use. That way the third-party component could be swapped out further on without affecting the client (assuming the interface of the wrapper is designed to be general enough to "fit" another third-party component).

Anders Fjeldstad
+1  A: 

You should take the purpose and the "volatility" of the framework in mind, but in general I would opt for wrapping it completely. This gives you much more flexibility and better encapsulation (think of exceptions for example)

Marc Wittke
+1  A: 

I'd go a step further, and write the functionality independent of the framework, and create "ideal" interfaces that you use.

Then, create a bridge between your functionality and the framework.

Wrapping someone's framework isn't necessarily a huge win if the wrapper is a one-to-one translation of the framework! You'll remove the binary dependency, but you'll still be conceptually coupled to the framework, making it harder to use your code outside of the framework.

kyoryu
can you kindly give an example of bridge?
Benny
Just a class (or series of classes) that translates between your "ideal" interface, and the one actually required by the framework.
kyoryu
so, it's kinda like a proxy
Benny
Adapters, bridges, and proxies are all kind of similar. Generally a proxy implies some kind of remote machine, an adapter converts values, and a bridge converts to another API. That's my understanding, at least.
kyoryu
yeah, your understanding is to the point.
Benny