Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6380825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:19:02+00:00 2026-05-25T02:19:02+00:00

I have been using two libraries, SFML and Box2D, while at the same time

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:19:03+00:00Added an answer on May 25, 2026 at 2:19 am

    The problem with the wrapper technique you’re describing is that your wrapper is transparent (in the true sense of that word) — every method in the library is still visible to you through the wrapper, with the same semantics, same preconditions, etc. You can “see right through” your wrapper.

    A transparent wrapper like that is useful to you only if you someday switch the underlying library to something that has identical semantics, or at least very nearly identical semantics. Consider this example. Let’s say the library was the std::fstream, and your application needed to read and write files, and lets say that you diligently wrote a wrapper:

    class MyFile {
        std::fstream* fst;
    public:
        void writeData(void* data, size_t count) {
            fst->write((const char*) data, count);
        }
        void readData(void* buffer, size_t count) {
            fst->read((char*) data, count);
        }
        // etc, etc.
    };
    

    Now let’s say you want (or need) to switch to asynchronous I/O with non-blocking reads and writes. There’s simply no way that your transparent wrapper is going to help you make that transition. The asynchronous read requires two methods, one to start the read operation and one to confirm that the read has completed. It also requires a commitment from the application that the buffer won’t be used in between those two method calls.

    When all is said and done, a library interface wrapper is useful only when very carefully designed to not be transparent (good interfaces are opaque). Furthermore, to be useful, the library you are wrapping must be something that you are intimately familiar with. So, boost::filesystem can “wrap” the pathnames for both DOS and Unix because the authors know intimately POSIX, UNIX and DOS pathnames and are designing the “wrapper” to effectively encapsulate those implementations.

    From what you’ve described, it seems to me that your effort is going to end up wasted. Simple is better than complicated, and unless the wrapper is really encapsulating something (i.e., hiding the underlying library), direct is better than indirect.

    That’s not a license to write spaghetti — your application still needs structure and isolation of the major components (e.g., isolate the UI from the actual calculations/simulations/document that your application provides). If you do that right, swapping the library some day will be a manageable task without any wrapper code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got two PostgreSQL databases that have been created using the same sql file.
I have been using git to keep two copies of my project in sync,
I have been using Castle MonoRail for the last two years, but in a
I have been experimenting with sending messages from two .NET Windows Forms applications using
We have been using CruiseControl for quite a while with NUnit and NAnt. For
I have been using Eclipse as an IDE for a short amount of time
I have been using C# for a while now, and going back to C++
I have been using Netbeans 6.1 for a long time and my debugger has
I have been using SCM for myself, but now I am working in team-of-two
I have been using phpunit for a while, starting with 3.5.8, subsequently upgrading to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.