Last active
January 13, 2016 15:53
-
-
Save lsem/6899acfac3ee67a61b44 to your computer and use it in GitHub Desktop.
Cross Platform Widgets Toolkit -- Naive Approach
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace ToolkitCode { | |
class IButton { | |
virtual void setTitle(const string &title) = 0; | |
virtual void doOnClick(std::function<void()> handler) = 0; | |
}; | |
class Win32APIButton : public IButton { | |
virtual void setTitle(const string &title) = 0; | |
virtual void doOnClick(std::function<void()> handler) = 0; | |
}; | |
class WinFormsButton : public IButton { | |
virtual void setTitle(const string &title) = 0; | |
virtual void doOnClick(std::function<void()> handler) = 0; | |
}; | |
class GTKButton : public IButton { | |
virtual void setTitle(const string &title) override; | |
virtual void doOnClick(std::function<void()> handler) override; | |
}; | |
class QtButton : public IButton { | |
virtual void setTitle(const string &title) = 0; | |
virtual void doOnClick(std::function<void()> handler) override; | |
}; | |
} | |
namespace ClientCode { | |
enum class UIFlavor { | |
GTK, | |
WinForms, | |
Win32, | |
QT | |
}; | |
class ProgramOptions { | |
uiFlavor: UIFlavor; | |
}; | |
void createUI() { | |
IButton *createDocumentButton, | |
*saveDocumentButton, | |
*loadDocumentButton; | |
ProgramOptions options = getActualOptions(); | |
if (options.uiFlavor == GTK) { | |
createDocumentButton = new GTKButton(); | |
saveDocumentButton = new GTKButton(); | |
loadDocumentButton = new GTKButton(); | |
} else if (options.uiFlavor == WinForms) { | |
createDocumentButton = new WinFormsButton(); | |
saveDocumentButton = new WinFormsButton(); | |
loadDocumentButton = new WinFormsButton(); | |
} else if (options.uiFlavor == Win32) { | |
createDocumentButton = new Win32APIButton(); | |
saveDocumentButton = new Win32APIButton(); | |
loadDocumentButton = new Win32APIButton(); | |
} else if (options.uiFlavor == Qt) { | |
createDocumentButton = new QtButton(); | |
saveDocumentButton = new QtButton(); | |
loadDocumentButton = new QtButton(); | |
} | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment