How to design an application in a modular way?

mac picture mac · Dec 8, 2009 · Viewed 10.3k times · Source

I am looking for pointers, suggestions, links, warnings, ideas and even anecdotical accounts about "how to design an application in a modular way". I am going to use python for this project, but advice does not need to necessarily refer to this language, although I am only willing to implement a design based on OOP.

Here's some context to understand where I come from and what I am trying to achieve...


My project will be a small application that will consume web services and display the results in a variety of ways, including:

  • notification popup containing just the result of the call
  • tab in the main window of the application with graphics plotted from retrieved raw-data
  • buffer of messages (visible on domand) where results from various services will pile up

The application will be released as free (as-in-speech) software, and for this reason I would like to make it really easy for other devs to write plugins/modules that will extend the functionality of the main application without needing to change the core code.

At this point in time, plugins should essentially enable a developer to activate a new webservice, by defining the provider, the data manipulation (if any) and the way the data will be presented to the user.

I have extensive experience in developing with drupal which has a powerful modular approach, but that also follows a non-object-oriented design, so I suspect that for python, drupal design might not be the optimal solution.

If this is of any importance - the core will be natively developed for GNU/Linux.

Thank you in advance for your time!

Answer

gavinb picture gavinb · Dec 8, 2009

Try to keep things loosely coupled, and use interfaces liberally to help.

I'd start the design with the Separation of Concerns. The major architectural layers are:

  • Problem Domain (aka. Engine, Back-end): the domain classes, which do all the actual work, have domain knowledge implement domain behaviour
  • Persistence: storage management for domain classes, database/filesystem layer
  • User Interface: the GUI, which talks to the domain classes
  • System Interfaces: talking to other systems, eg. networking, web services

The domain classes do the work, but don't know about the UI. The persistence layer knows about the domain classes, enough to save/load as required. The system interface layer abstracts away external systems, which lets you plug a simulator in behind while testing. The UI should ideally use MVC, for maximum flexibility.

Without putting too fine a point on it, one would not ordinarily look to Drupal as an exemplar of good architectural design. It has grown rather organically, and there have been many upheavals of the design, as evidenced by the regular plugin breakage upon system upgrades.

I would also echo what MicSim said, regarding carefully designing the plugin interface and writing multiple different plugins to exercise it. This is the only way to really flesh out the issues of how the app and plugins interact.