English
Topic 8. Records, enums, sealed classes, and pattern matching
Goal: learn to create validated values and closed models of alternatives, process them with exhaustive switch statements, and use stable record patterns.
Lecture contents
- Records and immutability — Values instead of boilerplate · Compact constructors and invariants · Example 1. A monetary value · Shallow immutability and defensive copies
- Enums — Enum defines a finite set of alternatives · Example 2. Planets with parameters
- Sealed types and patterns — Sealed restricts direct subtypes · Type patterns, scope, and null · Example 3. Sealed shapes
- Record patterns and deconstruction — Record patterns and deconstruction · Example 4. An arithmetic expression tree · Preview features and IDE tools