๐ WAYPOINT LESSON
Modeling the domain
โญ beginnerโณ 13 min read๐ Lesson 83 of 85
A record for Transaction, an enum for direction, validation that returns reasons โ a small domain model done right.
The types
public enum Direction { Income, Expense }
public record Transaction(int Id, Direction Dir, decimal Amount,
string Category, string Description, DateTime Date);
public record AddResult(bool Ok, string Error);
The record gives value equality for free (Module 11); the enum makes invalid directions unrepresentable โ Direction.Expense beats a magic "out" string the compiler can't check. decimal for money (Module 2): exact base-10 arithmetic, no binary-rounding surprises.
Validation as data
AddResult returns why an entry was rejected instead of throwing: Ok = false, Error = "amount-must-be-positive". Callers branch on the result; no exception cost, no control flow by crash. The error strings are the API โ tests pin them.