Solution (source code)

= Solution

The <UML class diagram> separates text shared by every displayable item from numeric formatting shared only by numeric items. A dashed hollow-triangle arrow denotes realization of a <Java interface>; solid hollow-triangle arrows denote <class inheritance>. Both kinds of arrow point towards the more general type.

\Image[/past-exam-of-the-computer-science-course-of-the-university-of-oxford/2015/object-oriented-2015-data-hierarchy.png]
{title=Data interface realization and inheritance for string, integer and real display items}

`AbstractData` owns alignment and computes length from the current rendered text. `NumericData` adds the minimum digit width. `IntegerData` and `RealData` each own their numeric value, while `RealData` alone owns the minimum number of decimal places. The numeric formatting <object methods> do not belong on `Data`: ordinary text has no meaningful `setPlaces` operation. The design choice is
$$
\boxed{\text{shared alignment in AbstractData; shared numeric width in NumericData}.}
$$