Search⌘ K
AI Features

Exercise: Transforming Shape Area Calculation

Explore how to transform shape area calculation code in Java by applying test-driven development and SOLID principles. Understand how to refactor existing code for rectangles to follow Single Responsibility and Open/Closed principles, enabling easy extension to new shapes like circles. Gain hands-on experience improving code design to enhance flexibility and maintainability.

Task and requirements

The provided code calculates the total area of rectangles but does not adhere to SOLID principles. Your task is to refactor the code to make it conform to the SOLID principles, especially the Single Responsibility Principle (SRP) and the Open/Closed Principle (OCP).

  1. Refactor the code to separate ...