Editorials

Open/Closed and Multiple Versions

Every year or so I come back around to the SOLID principles of software development. They are easiest to implement in object oriented languages, but the principles still apply. If the SOLID acronym is new to you, take a trip to Wikipedia for an explanation.

Today I want to talk about the O in solid, which stands for Open/Closed. Open means that software is open for changing implementation, but closed for changing the interfaces. So, if you are using Java, Visual Basic.net or C#, you could not add a public property to a class that has shipped. However, you could inherit from that class, and add the new property in the new class. This assures that all old code continues to work, but new code has needed additional functionality.

In languages that support interfaces, this is the better object to version. Let’s take a person object, for example, having a title, first name, middle initial and last name. This is version 1 of a person interface. In the next release of your software you want to add a date of birth property. To do this, you can create a new interface for person V2, inheriting from Person V1, adding the new property, Date Of Birth. Now you can modify you class that implements the original Person V1 interface, and add the Date Of Birth property. The class now inherits from both Person V1 and Person V2. As a result, the class can create either a Person V1 or Person V2.

Of course this is a very simplistic example. And there is a lot of work you must do for object instantiation and method implementations to allow a single class to work with both versions. It’s not so bad when you are simply adding a property. When you add methods to the different versions it can become a little more sophisticated.

Today I thought I would open up discussion with the question, “How important is it for your software to enable multiple versions concurrently?” A good example we all work with are the libraries for java or Dot net. The newer libraries are often reverse compatible. Get into the conversation by leaving your thoughts below.

Cheers,

Ben