What is "ReadonlyRectangle"? Is it just an interface that only exposes read-only methods; or is it an explicit promise that the rectangle is immutable?
Perhaps we could go with even more classes. "Rectangle" and "Square" for the read-only methods, without any implications about mutability. "MutableRectangle" and "MutableSquare" for mutable implementations; "ImmutableRectangle" and "ImmutableSquare" for immutable implementations.
- "Rectangle" has methods "getWidth" and "getHeight".
- "Square" has a method "getSide".
- "ImmutableRectangle" implements "Rectangle".
- "ImmutableSquare" implements "Rectangle" and "ImmutableRectangle" and "Square".
- "MutableRectangle" implements "Rectangle"; has extra methods "setWidth" and "setHeight".
- "MutableSquare" implements "Rectangle" and "Square"; has an extra method "setSide".
...or you could just give up, and declare two classes "Square" and "Rectangle" (mutable) that either have nothing in common, or they just both extend some "Shape" class that can paint them and calculate the area.