1. Open/Closed
Depending on an abstraction instead of switching on the concrete type
AreaCalculator works. It adds up the area of every shape it has been given, and the tests pass.
It does it by asking each shape what type it is and then doing that type’s arithmetic itself — which means the calculator has to be edited every time a new kind of shape exists.
Shape already declares area(). Rewrite total() so that adding a shape the calculator has never heard of needs no change here at all.
Run compiles every file and runs Tests.java — the tests you can read.
Submit runs those again, then applies 1 requirement you have not seen, one at a time.
Your code is never edited. Each requirement is added to the project as it stands. If the design is right, nothing you wrote has to change.
- Ctrl/⌘ + Enter runs the tests
Run the tests to see where you are.