Search code examples
c++paradigms

Generic interface for big projects


Let's say you are writing a bigger project and you have to use 3rd party libraries. So your complete project will be depended on these libraries.

I thought instead of using those 3rd party libraries directly, I would write some sort of an wrapper library or an interface that would look something like this.

void myMainloop(...){
    3rdpartyMainloop(...);
}

So if the 3rd party library gets outdated I just could switch to another library by just integrating it in my wrapper library.

Is this a good thing to do? What alternatives do I have?

I am a little bit worried that if I have two libraries that are essentially doing the same thing but are completely different designed, that it is not possible to find an generic interface for both.


Solution

  • You could write a generic interface to which you could adapt one or more 3rd party libraries. However, it would require very careful design and planning, not to mention a huge amount of development effort if you're talking about a library of the size and scope of Qt. You'd first have to design your interfaces, then implement those interfaces for each library you wanted to be able to plug in.

    Bottom line, it's a very lofty goal, and you're not likely to end up with anything that's truly "generic". At best, you'd probably have to dumb down the interface to the point where you're not taking advantage of many of the features that each library has to offer. Also, you'd likely introduce overhead that would diminish your applications performance, so keep that in mind if performance is critical.

    I'd say just choose the library that suits your needs the best, unless you want to roll your own, which I doubt.