I want to write an application where I would delegate certain functionalities to 3rd party libraries. To make sure the code remains modular, I want to put these libraries behind an interface so I can swap out the underlying implementation when needed, or even use multiple different implementations simultaneously.
Specifically, I want to make a GUI application and use either Qt or wxWidgets to implement the GUI elements. Both have a basic window and a dialog that inherits from it, so intuitively my interface would look something like this:
class Window
{
virtual void open() = 0;
// ...
};
class Dialog : public Window
{
virtual void open() override
{
// ...
}
// ...
};
Qt implements these using QWidget and QDialog, while wxWidgets uses wxWindow and wxDialog respectively. So my implementation wrappers would look something like this:
class QtWindow : public Window
{
// Uses QWidget internally
};
class QtDialog : public Dialog, public QtWindow
{
// Uses QWidget internally
};
class wxWidgetsWindow : public Window
{
// Uses wxWindow internally
};
class wxWidgetsDialog : public Dialog, public wxWidgetsWindow
{
// Uses wxDialog internally
};
The main draw of using such a class hierarchy is that I can ensure that every implementation fits the same interface, i.e any change I make to Window or Dialog must then propagate to changes in the Qt and wxWidgets wrapper objects as well. The obvious downside is the diamond inheritance, which I could solve via virtual inheritance, but it just feels like bad design altogether.
Is there a design approach that would work better in the above scenario?