Linearization rules

Linearization rules in Scala are defined and exist in order to ensure well-defined behavior. The rules state the following:

  • The linearization of any class must include the unmodified linearization of any class (but not trait) that it extends.
  • The linearization of any class must include all the classes and mixin traits in the linearization of any trait it extends, but the mixin traits are not bound to appear in the same order as they appear in the linearization of the traits being mixed in.
  • Each class or trait in the linearization can appear only once. Duplicates are ignored.

We already saw in some of the previous examples that it is not possible to mix in traits that have different base classes or to mix in a trait into ...

Get Scala Design Patterns - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.