Simplifying Maintenance with SRP
Explore how to refactor to adhere to SRP, streamlining future maintenance and enhancing code readability.
Refactoring for single responsibility
To see the value of applying SRP, let’s consider a piece of code that doesn’t use it. The following code snippet has a list of shapes that all get drawn when we call the draw() method:
We can see that this code has four responsibilities, as follows:
Managing the list of shapes with the
add()methodDrawing all the shapes in the list with the
draw()methodKnowing every type of shape in the
switchstatementHas implementation details for drawing each shape type in the
casestatement
If we want ...