Patterns to refactor common code in multi-platform software
- by L. De Leo
I have a Django application and a PyQt application that share a lot of code. A big chunk of the PyQt application are copied verbatim from the Django application's views. As this is a game, I have already an engine.py module that I'm sharing among the two applications, but I was wondering how to restructure the middle layer (what in Django corresponds to the largest part of the views minus the return HttpResponse part) into its own component.
In the web application the components are those of a classic Django application (with the only exception that I don't make any use of models):
the game engine
the url dispatcher
the template
the views
My PyQt application is divided into:
the game engine
the UI definition where I declare the UI components and react to the events (basically this takes the place of the template and the url dispatcher in the Django app)
the controller where I instantiate the window object and reproduce the methods that map the views in the Django app