I'm trying to reach a better understanding of the Open/Closed principle. I'm familiar with reference material such as
and Jon Skeet's exploration of the ideas, and the related concept of Protected Variation.
I have a nagging feeling that I still haven't got to essence of the Open/Closed Principle. One approach I have to increasing understanding of a concept is to explore the negation or inversion of the idea. I'm having trouble coming up with a concrete example of a violation of the Open/Closed principle - my hope is that if we have such an example we can point to it and say "Look at the unfortunate results of designing that way, how much better things would be if we were Open/Closed."
So, the question. Can you give a non-trivial example of, say, a Java class that is Closed for Extension or Open for Modification and why that would be a bad thing.
Obviously there are trivial cases such as making a class final so inheritance is barred but I don't think that's the core of the Open/Closed principle.
Aucun commentaire:
Enregistrer un commentaire