liveBook · Manning

Degrees

As explained in Data-Oriented Programming in Java

A book-specific data type representing angular degree values while enforcing the domain constraints of a contact angle.

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

How Data-Oriented Programming in Java covers it

How deep it goes
Defines a record invariant, integrates it into Measurement, and contrasts concrete degrees with a broader Angle abstraction.
Examples
Demonstrates contact-angle validation, Measurement records, grouped measurements, and alternative degrees, radians, turns, and arc-seconds types.
What it assumes
Assumes Java records and type-system familiarity while reasoning from domain meanings and constraints.
What you can do after
Build it from scratch as a Java record that rejects out-of-range angles and carries its domain meaning through models.
How it connects
Connects domain modeling, type systems, Measurement, Angle, and architectural boundaries around raw representations.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data-Oriented Programming in Java. The section links point to the parts of the book it draws on.