easy

Design a Shape Calculator

Design a shape hierarchy with area and perimeter calculations. Support circles, rectangles, and triangles with an extensible design that allows adding new shapes without modifying existing code.

Suggested time: 45 minutes

Loading the workspace...

About this problem

A shape calculator sounds like a collection of geometry formulas. But a well-designed system must enforce polymorphism so that calculating total area across mixed shapes requires zero type checking, validate dimensions at construction time so invalid shapes are structurally impossible, support aggregate operations over large collections with parallel computation, and allow new shape types to be added without modifying any existing class. The design challenge is building a hierarchy where every shape is interchangeable through a single abstract interface.

What your design needs to cover

  • Area and Perimeter Calculation

  • Aggregate Calculations

  • Dimension Validation

  • Shape Comparison

Key challenges the editorial covers

Learn from other designs

Related problems

Guides