Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should outside libraries be wrapped?

I have been using two libraries, SFML and Box2D, while at the same time taking great pain to ensure none of their functions or classes are exposed in the main body of my code, hiding them behind classes that serve little more than to act as a mediator between my code and the library itself. My mediators take the following form:

    class MyWindow{
    public:
        // could be 10 or so functions like below
        int doSomething(int arg){
           return library_window->doSomething(arg);
        };
    private:
        library::window * library_window;
    };

The benefit to this, at least what I've been told, is that my main code body is not reliant upon the library, in such a way that if it changes or I choose to use a different one, say SDL or OpenGL in place of SFML or something, I can switch by merely amending the mediator classes. But the pain of having to code an access point into every feature I want to use is painful and repetitive...

Is this really how professional programmers are supposed to treat external libraries? And is it worth it?

Am I even doing this right?

like image 818
Anne Quinn Avatar asked Dec 16 '22 10:12

Anne Quinn


1 Answers

Not worth it. Just use the libraries. If you end up wanting to change to a different third-party library, you'll end up needing to change your application code anyway...otherwise what was the point of changing in the first place, if everything works the same in both versions anyway.

Friends don't let friends over-engineer. Just say no.

like image 165
John Zwinck Avatar answered Jan 05 '23 00:01

John Zwinck