Contents
Why do you need a wrapper around a third party library?
The basic reason to write a wrapper around a third-party library is so that you can exchange that third-party library without changing the code that uses it. You can’t avoid coupling to something, so the argument goes that it is better to couple to an API you’ve written.
Is it good idea to avoid binding code to third party libraries?
As a general principle, is it a good idea always to avoid binding all components of the code to the third-party libraries and instead go via an encapsulating wrapper to avoid the pain of change?
Why do developers use third-party libraries for core features?
Libraries typically make trade-offs in order to be able to cover a wide spectrum of use-cases. By using libraries for your core features you are making these very same trade-offs. For example, if image loading is central to your business, existing image loading libraries might not be the best fit.
How are libraries kept separate from application code?
The library’s code is naturally kept separate from the rest of your application code, and communication takes place across well-defined boundaries (the library’s API). If instead, you opt to develop a feature yourself, it might be hard to decouple it from the app’s code.
How to write a wrapper for a C library?
Assuming that the C library’s allocation/deallocation instances are create_instance and destroy_instance, and it exposes a function called call_function, and it does not provide an API for deep copying instances, this will work: Thanks for contributing an answer to Stack Overflow!
What makes a library a leaky abstraction or wrapper?
Libraries always introduce a number of assumptions into your code. Wrappers are a leaky abstraction. Wrappers often hide rich features offered by the library by only offering a small slice of the functionality.