The principles of extending software

I was quite productive today - even with some hangovers from last night :)

I done some consultant work for a customer that wanted following GoogieSpell functionality:

  • Support for dependent text boxes
  • Support for "Ignore" and "Ignore all" menu items
  • Support for "Change all" menu item
  • Various other tweaks and bug fixes

Now the extensions had to be made so the customer could upgrade to future version of GoogieSpell seamlessly. I chose not to put the changes inside GoogieSpell since it would make the code base too complex - therefor I had to code smart ;)

Now the changes that had to be made weren't trivial - since GoogieSpell wasn't build to support dependent text boxes or additional menu items that could manipulate "everything". I thought a bit about the problem and I remembered that I have had a computer science course called Software Architecture, where I learned the 3 principles of great software design (taken from the legendary GOF book):

  • 1. Program to an interface, not an implementation
  • 2. Favor object composition over class inheritance
  • 3. Consider what should be variable in your design

Now, I coded GoogieSpell in JavaScript, which lacks classes - how can I use the above principles? Good question, but basically their definition is rather abstract and I mostly use their way of thinking. The things I look at when I try to design software is:

  • Low coupling: The code parts should be as independent as possible
  • High coherence: The the code parts should be as coherent as possible. I.e. no mix up of functionality inside code parts

Now, the trick is that all the design patterns are built up from the above 2 principles...! By having low coupling one can reuse and upgrade one of the code parts without affecting other parts. By having high coherence one know that this class or function does this and this and nothing else.

Something I am beginning to use in JavaScript is insertion of holes inside my code where someone else can insert their code. I have done this with observers:

  • lang_state_observer: A function that another person can fill to get notified when the language is changed.
  • show_menu_observer: A function that another person can fill to get notified when the menu is shown.

And extensions:

  • custom_menu_builder: An array of an evaluator function and a menu builder function. This way one can create custom menus if the evaluator returns true.

Little holes can extend GoogieSpell into this:

I have released GoogieSpell 3.6 with a lot of improvements and some bug fixes. AJS 2.3 is also out and has support for events.

Code · Code improvement · Design 13. May 2006
© Amir Salihefendic. Powered by Skeletonz.