I am talking about wrappers for third-party libraries. Until recently, I tried to provide a fairly general shell, so I could easily switch libraries if necessary. However, this turned out to be almost impossible, since libraries can vary greatly even with regard to how basic concepts are handled.
So, the question came to me why use wrappers at all. (In the past, experienced coders encouraged me to write wrappers for third-party libraries.) I came to the following conclusions; please tell me if they are wrong or you have something to add.
- If the library is not widely used in the application (for example, it is used only by one or two classes), do not write the wrapper at all, just use it directly. (Especially if it is a portable library.)
- When you write wrappers, don't think that you can make a wrapper of the same size. Write something suitable for lib strengths.
- ... But in some cases, you can still generalize the shell to make it easier to switch libraries. (For example: most graphics libraries use images and fonts.)
- Wrappers are useful when the library offers more functionality than you need. You can hide unnecessary functions in the shell.
- In the case of C libs (if you use C ++), you can also write a wrapper to help you with automatic memory management.
, (dis) ?