Let's go back to the shapes application we introduced when talking about the command pattern. We applied the command pattern, so we have to redo the operations implemented. It's time to add a save functionality.
We might think that if we add an abstract Save
method to the base shape class and if we extend it for each of the shapes, we have the problem solved. This solution is maybe the most intuitive, but not the best. First of all, each class should have a single responsibility.
Secondly, what happens if we need to change the format in which we want to save each shape? If we are implementing the same methods to generate an XML out, do we then have to change to JSON format? This design definitely does not follow the open/closed principle.