Degrees makes a contact angle’s meaning explicit instead of storing it as an unrestricted double. The domain permits values from -180° through, but not including, 180°. section 3.3
Constrain the value at construction
A Java record can reject invalid angles immediately: record Degrees(double value) { Degrees { if (!(value >= -180.0 && value < 180.0)) throw new IllegalArgumentException("Invalid angle"); } }. Invalid states become construction failures rather than values that travel unnoticed through the program. section 3.3
Using Degrees in Measurement preserves the domain meaning through access, grouping, and calculations. The compiler prevents the angle from silently becoming an unrelated numeric value. section 3.3
Degrees is intentionally specific to water-droplet angles measured along a flat surface. A broader Angle abstraction can support radians, turns, or arc-seconds, but requires stricter boundaries where raw degrees enter the program. section 3.3.1
Listing 3.15 capturing our specific meaning of Degrees in a type
record Degrees(double value) { #A
Degrees {
if (!(value >= -180.0 && value < 180.0)) { #B
throw new IllegalArgumentException("Invalid angle");
}
}
}Inspect the record definition that captures the contact-angle range and rejects invalid values. section 3.3
Listing 3.18 An alternative design that models angles abstractly
interface Angle {/*...*/} #A
record Degrees(double value) implements Angle {/*...*/} #B
record Radians(double value) implements Angle {/*...*/} #B
record Turns(double value) implements Angle {/*...*/} #B
record ArcSeconds(double value) implements Angle {/*...*/} #B
// and so on...
record Measurement(
String id,
int daysElapsed,
Degrees contactAngle
Angle contactAngle #C
){/*...*/}
Compare the concrete Degrees representation with an Angle interface supporting multiple angular units. section 3.3.1
