Abstraction ideas

An interface I is a definable abstraction over an entire class of further, orthogonal abstractions. In general, two different implementations T1 and T2 of an interface I are completely unrelated; notably, one is not substitutable for the other. It describes operations and fields on each kind of implementing structure T that must be provided by such a T. The operations and fields supported by a T that implements I are accessed as top-level functions and variables, conveying that no knowledge of T’s internal structure is apparent to the accessing context.

A trait T is a definable abstraction over concrete representations. If T implements some interface I, then it is considered one such implementation of I and other such implementations of I are unrelated to T. It describes operations supported by every concrete representation O with trait T; these operations are invoked as dotted methods on O, conveying a dependence on O’s state in addition to any arguments.

An object O is a concrete representation of some trait T that abstracts over all the possible values (i.e. state configurations) of this representation. If O extends some trait T, then any value with representation O supports the operations of both T and O combined. An object describes not only operations supported by each of its values but also the structure comprising the state of the representation.

An object O is embodied by values with representation O, so O can be considered a set of such values, a type. A trait T is embodied by such representations, so T ranges over their sets of values. However, since T describes the operations of each representation and thus of each value, T designates an additional set of values — one that encompasses the sets for all representations of T. That is, T designates a supertype of the types of all its representations. An interface is embodied by further abstract structures rather than values, so it cannot be considered a true type. Instead, it can be viewed as a higher-kinded type, a metaclass, or a type predicate.

Below are some examples of the three levels of abstraction:

* interface Collection

  * trait List
    * object ArrayList
      * ArrayList([1, 2, 2])
      * ArrayList([5])
      * ArrayList([])

    * trait ConsList
      * object Cons
        * Cons(1, Cons(2, Cons(2, Nil)))
        * Cons(5, Nil)
      * object Nil
        * Nil()

  * trait Set
    * ...

* interface Cloneable

  * trait String
    * ...

  * trait List
    * ...

(Note the extra level of abstraction via traits in the List hierarchy.)