Originally posted by Joe Nguyen:
According to the open close priciple: Software entities (classes, modules, functions etc) should be open for extension, but closed for modification.
Two important things to notice:
- the principle is talking about *extension*, not bug fixing
- it says that entities should be designed a way that you can extend them without modifying them. When you need to extend a class that isn't designed for that kind of extension, you are simply out of luck - you need to modify it.
Often the best way to modify it in that case is to modify it in a way that it better conforms to the OCP, that is, that the next time you need to extend it in a similar way, you don't need to modify it again.
That might require more modification than is comfortable without having an extensive
test rig to confirm that you didn't break something. On the other hand, without making those changes the system is likely to become unmaintainable not too far in the future...