The basic principle entitled Open/Closed of the SOLID acronym is defined as “Open for extension, Closed for Modification.” This principle is implemented by utilizing the other SOLID principles in conjunction with object oriented development patterns.
If you are new to SOLID and/or new to patterns, this can be overwhelming; it appears to be a form of nirvana that one never achieves. I’ll try and provide a high level description hoping to encourage you to dig deeper.
Let me start by asking, “How often have you written software that has never had to be extended?” My experience has been that software always seems to need enhancements at some point. You need to add new functionality to your software which has been tested and perfected over time. How do you make modifications, sometimes major modifications, without breaking your existing code? Applying the open/closed principle you would not modify the existing code; rather, through implementing software development patterns, you would add new functionality, taking advantage of the existing software, without changing the way it works internally.
That is the reason that SOLID is an acronym. Each of the principles work hand in hand and cannot stand alone. For example, the Single Responsibility pattern we reviewed yesterday provides a framework for Open/Closed. If each object has a single responsibility, it is a lot easier to lock them down (Close) while still adding new functionality at a later time (open).
Consider the Dot Net framework. Each new version supports the features of the previous version (closed) while adding new features (open) that may even be based on features from the previous version. Generic Collections are a good example. Dictionaries are released in one version only to have additional enhanced dictionaries in later versions of the Dot Net framework.
If you would like to see an example of code techniques implementing Open/Closed, I found a great article in MSDN magazine by Jeremy Miller, http://msdn.microsoft.com/en-us/magazine/cc546578.aspx, from 2008 demonstrating how the SOLID principles may be implemented through different object oriented patterns.
Let me warn you that he demonstrates patterns that any single one can be found as a whole chapter in a book teaching patterns. So, if you are overwhelmed don’t be surprised…go find a pattern tutorial. I guarantee it will be worth your time.
Do you have other examples for implementing the Open/Closed principle? Do you think you can simplify the concept making it easier for a beginner to understand? Please drop me a note with your comments to btaylor@sswug.org.
Cheers,
Ben
$$SWYNK$$
Featured Article(s)
Troubleshooting problems with Reporting Services in SQL Server 2008 R2
This article describes the problems you can have with SQL Server 2008 R2 Reporting Services.
Featured White Paper(s)
How to Use SQL Server’s Extended Events and Notifications to Proactively Resolve Performance Issues
read more)