A sealed trait defines a closed type hierarchy: every permitted subtype must be declared in the same source file. This makes it suitable for algebraic data types, where the known constructors describe the complete shape of a value and let the compiler check pattern matches for exhaustiveness. section 3.4 section 3.6
A typical hierarchy places case classes and case objects in the companion object. For a list, Cons represents a head and tail, while Nil represents the empty case; recursive operations can then match every permitted constructor. section 3.4 section 3.6
A sealed list hierarchy
sealed trait List[+A]: def size: Int object List: case class Cons[+A](head: A, tail: List[A]) extends List[A]: def size: Int = 1 + tail.size case object Nil extends List[Nothing]: def size: Int = 0 The closed set of constructors lets size handle both cases directly and prevents external code from adding an unanticipated list variant. section 3.4

