views:

39

answers:

2

I have to use a 3rd-party library and I want to write code in which business logic is decoupled from the library vendor, so that in the future, if I change the library that I am using, there is minimal impact on my business logic.

Please suggest me Design pattern that will be highly effective. I would appreciate if you can suggest me some samples/articles/books.

+5  A: 

Use the Adapter or Facade patterns, depending on how complex the library is.

Essentially you create a library-agnostic interface and write a wrapper for all the functionality you will use from the library and code you application using the interface.

If you ever want to change third-party libraries, you just have to make a wrapper for the new library that has the same interface.

This is typically how applications avoid being tied to a library. However, if the library you are using is fairly mature and the likelihood of changing libraries is low, I would not bother doing this, following the YAGNI and KISS principles.

Ben S
sat
A: 

Wrap the functionality of the 3rd party libraries in one class, (highly possible will be something like a Facade pattern) and from this moment deal only with your Facade. Wikipedia: http://en.wikipedia.org/wiki/Facade%5Fpattern

fritzone