How to design an application in a modular way?


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!

12/8/2009 9:17:22 AM

Accepted Answer

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.

12/8/2009 11:57:54 AM

As you will deliver some basic functionality with your app, make sure that you code the part that should be extendable/replaceable already as a plugin by yourself. Then you'll best get a feeling about how your API should look like.

And to prove that the API is good, you should write a second and third plugin, because then you will discover that you made a lot of assumptions when writing the first one. Normally things clear up a bit after doing this 2nd and 3rd step.

Now, you should write one more plugin, because the last plugins you wrote resemble the first one in type, input data and presentation (maybe yet another weather webservice). Choose something total different, with absolutely different data, and you will see your API being still too tailored. (Else you did a good job!)

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow