Object orientation

Scala is an object-oriented language as well as a functional one, and the two are not separate layers: a class is a value, a trait is a type a class can mix in, and a function is an object with an apply method. This part takes the object side from the constructor to equality, and the case classes of the next part are built on it.

The seven lessons follow one class through its life: it is constructed, its companion makes one, a trait adds behaviour, a base class requires it, the visibility decides who sees it, an opaque type hides its representation, and equals decides when two of them are the same value.

025 Classes and constructors the primary constructor, val and var parameters, auxiliary constructors and private members Open 026 Objects and companions a singleton, a companion object, apply and unapply, and a factory Open 027 Traits and linearization a trait with state, super calls in a stack of traits, and the order they run in Open 028 Inheritance and abstract members extends, abstract members, override, final, and an abstract val Open 029 Export and visibility export a member of a field, private, protected, and private to a package Open 030 Opaque types a type that is a String at run time and a new type at compile time, with its companion Open 031 Equality == against equals, canEqual, a case class, a class with its own equals, and eq Open

Lessons