The Importance of Modular Architecture

By | August 19, 2006

If you are a software engineer and somewhat up to date with the latest techniques and methodologies you will have heard of modular design. Even though a lot of developers seem to know what it is, very few use it. Today I hope to help you make the final step to use modular design.

First lets go over a quick list of why you should use modular design in all of your solutions:

  • Similar functionalities are grouped together, well if you do it correctly anyway
  • The code is easier to maintain, a big plus for most people!
  • A complete stranger will have little difficulty understanding the basic setup of the project. (For the more techies this is the architecture and interface lay-out of the solution)

Personally I believe that these points should be enough of a reason for everybody to use a modular design. So why do some, especially the older, software architects and designers still opt for a design without modular setup or with flawed setup. Easiest explanation I could find is that this is the way they were taught. Growing up with C or Pascal you had little choose but to work like that.

What makes a modular design successful is that it is not only easier to understand the existing code, but that it should be ‘relatively’ easy to add new functionalities. Lets take a simple example (I just love those). If you have a document editor you would have some functions that describe how the document is saved, loaded and displayed. You may have noticed these are all related to a document. So you could group these type of functionalities in a document class.

But a document editor should also be able to work with different fonts. Each font having a default height, style and character set. Now some might put this in the document, after all it is display related. But if you were to make it modular you would have to be able to remove this functionality or add new fonts without changing the remainder of the application. Well no big changes any way, some minor changes are unavoidable. So I would say make a new class dealing with the displaying and embedding of the fonts.

The same holds true for printing a document. Loosely spoken a document class could contain a function for printing. But which one of the following is true. Does the document need the printer to work or does the printer need the document to work. I’d say it is the latter, after all the document does not need the printer to properly work but the printer can’t print without a document.

This also tells us why many people find it difficult to make a good modular architecture. For every functionality the solution needs to have you need to figure out its dependencies. I usually try to find out which functionality can’t work without the other, along with some good tricks I was taught. But if you haven’t had this training I’d strongly suggest picking up a book like ‘Software Architecture In Practice’. These books help a lot, trust me on this.

Now in the example above it would be very easy to add or remove a feature without having to change to much of the code. I could just add or remove a class to the already existing application. Or better yet someone that knows little about the original application could write the ‘plug-in’ and I could integrate it in the existing application.

Leave a Reply