Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One key different between mixins and traits is that mixins have fields, whereas traits do not. Paraphrasing from the original paper, a trait:</p> <ul> <li>provides methods that implement behavior</li> <li>requires methods that parameterize the provided behavior</li> <li>do not specify or access any fields</li> <li>are symmetrically composed</li> <li>can be nested, equivalent to flattened traits</li> </ul> <p>At first glance the third point looks like it is broken in the Scala implementation. However, traits can only access public fields, which are protected by implicit getters and setters. The paper goes on to describe that this is acceptable for the implementation of traits.</p> <p>You point out that a key feature of traits is that methods can be renamed when you import them. This is not possible given the constraints of the JVM. A coherent discussion of this can be found here: <a href="http://scala-programming-language.1934581.n4.nabble.com/Trait-method-aliasing-td2322026.html" rel="nofollow">http://scala-programming-language.1934581.n4.nabble.com/Trait-method-aliasing-td2322026.html</a>, particularly the posts by David Pollak.</p> <p>Finally, my answer to your general question is "sort of". To elaborate, whilst Scala traits are not strictly traits as defined by the paper, they are not strictly mixins either. Either way, it is probably best to use them like they were traits and keep to their design principles. </p> <ul> <li>Keep them small, with the intent of reusing them. </li> <li>Specify behavior not state.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload