I want to develop an application which has a graphical user interface that could be developed by using different widget toolkits. For example I want to use Qt, GTK+ or even ncurses as a building block for my user in开发者_StackOverflowterface for the same application. Moreover users could choose which GUI implementation will be used during the next startup of the application without recompiling it first. I wonder what are possible design strategies and design patterns used in the implementation of this design?
The classic design pattern for multiple GUIs is MVC.
You have one model (application data and rules), the controllers (one per view) - these control UI interactions and mediate between the UI (views) and the model.
You can have different views talk to the controllers - one view can be Qt, another GTK+ or even a console application.
Why would you want that?
Each toolkit has its own strong points and weaknesses. If you want to design something that will work with them all, you will be limited by the cumulative sum of all of the weaknesses and gain none of the strong points.
For instance if you're using Qt then you won't be able to use QT's signals and slots. that will make writing the GUI and the interaction with it quite painful. You'll basically need to write a whole wrapper layer around something that is already a wrapper layer (to the native APIs)
I see no possible reason why a user would care to choose between Qt or GTK+ or ncourses. just select one thing and stick with it.
精彩评论