My latest article entitled The Open Closed Principle is available in the June 2008 edition of MSDN Magazine. I tried to present both the motivation for following the OCP and some design strategies (besides the obvious Plugin example) and related principles to bring your design closer to being “Open for Extension, but Closed for Modification.”
If you’ve never heard of the Open/Closed Principle, think of doing an addition to an existing house. What sounds easier, laying all new bricks for an all new room, or changing the layout of existing rooms with a reciprocating saw? An Open/Closed design allows us to extend the system with new code instead of having to potentially screw up existing code that works today.
Lastly, if you’ve read about the OCP before and think the OCP == “Plugin Pattern,” go give the article a read, because that’s not the entire story.
This is the first in a bi-monthly series of articles called Patterns in
Practice on software design fundamentals. The next article (Object
Role Stereotypes/Responsibility Driven Design) is already completed, but I’d be perfectly happy to
take requests. I think the next two leading candidates are “design
vectors” (i.e. better designed code by moving in the direction of this, that, or the other) and treating Inversion of Control as a design pattern
independently of IoC tools.
Related Posts to the Article:
- Just some little things to help you CodeBetter
- Orthogonal Code
- Using the Chain of Responsibility Pattern
- On Writing Maintainable Code
- Be not afraid of the Visitor Pattern, the big, bad Composite Pattern, or their little friend Double Dispatch