[edit] I'm not really talking about a wrapper class here either (see below), but hopefully it's close enough . . . . [/edit]
Well -- okay. It will have to be a contrived example I'm afraid.
Let's say I have a program which can output to the command line with cout, or to a console using ncurses (I'll explain what that is in a minute). I might then have the class Screen as my wrapper class.
Code:
class Screen {
public:
virtual void display_message(std::string text);
};
So for the cout implementation, this is really easy.
Code:
class ScreenCout : public Screen {
public:
virtual void display_message(std::string text) {
std::cout << text << std::endl;
}
};
But with the ncurses implementation, suppose I also add the capability to scroll back to see the history of what has already been displayed. I'll have to store each line of text as it is printed so that it can be re-displayed as necessary. A sketch of the class might look like this.
Code:
#include <vector>
class ScreenNCurses : public Screen {
private:
int current_top;
std::vector<std::string> displayed;
bool at_bottom;
public:
virtual void display_message(std::string text) {
displayed.pish_back(text);
if(at_bottom) scroll(1);
}
protected:
virtual void scroll(int lines) {
current_top += lines;
// repaint lines starting at current_top from displayed[]
}
};
You see how completely different the implementation is? They both do the same thing, but the ncurses version has to remember everything that was printed to provide history.
That actually isn't a very good example. It's a good example of an interface with differing implementations, but a wrapper class typically provides more or less the same functionality using e.g. different libraries. But I didn't want to have to make up too many different libraries so I guess I'll let it be.