No such thing as a small change | |
PerlMonks |
Creating GUI's that work across several versions of Tkby leriksen (Curate) |
on May 28, 2006 at 11:52 UTC ( [id://552162]=perlmeditation: print w/replies, xml ) | Need Help?? |
I have recently been working on a Perl/Tk app that I plan to host on Sourceforge for future development. As part of the preparation for this step, I asked a few people, with knowledge in the field this apps deals with, to review my approach and the usefulness of the app. And thats where my problems began ...
Firstly, not everyone I gave the app to had the most recent version of Tk installed, and they were not in a position to easily update the installed version (legacy apps bound to their old version of Tk, not their server etc.) And this was a problem for me, because I had developed against the most recent version (804.027), and not every widget I used in my app was supported in their older Tk install. For example, the Tk::Spinbox is not available in older Tk's. Also, some widget are available in all Tk releases, but some of the options those widgets support vary from release to release. For example, in the Tk::Listbox widget, the 'listvariable' option is not available in earlier Tk releases, requiring the user to manually populate the widget. So, how can we support multiple versions of Tk (or any module with a long history and a varying interface) ? My solution involves
In order to demonstrate these 3 steps with some code, lets imagine we have an application that needs to present some options for a user to select. For some options we want the user to select or enter a number, for others we want the user to select a value from a list. We have written this option display and processing code to all exist in one package/namespace we call Application::Option
It strikes me that this technique would also work well with other long-lived modules, like DBI, members of XML:: or Net::family etc. The key is to generalise what you want, then write specific subs to do that general thing for each version of the module you intend to support. I think that in Pattern language this is an example of an Adapter pattern. ...reality must take precedence over public relations, for nature cannot be fooled. - R P Feynmann
Back to
Meditations
|
|