Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you are coming from Java, it can sound strange at first (it was the same for me), but actually now I find it's more regular syntax then Java's, where I need to explicitly say whether I want to <code>implement</code> or <code>extend</code> other class/interface. But I think it's more question of the personal taste. </p> <p>It does not actually matter whether you are saying <code>extends</code> or <code>implements</code>. They both represent the same kind of relationship between two things: <strong>is a</strong> (in contrast to delegation and composition, which represent <strong>has a</strong> relationship). Here, for instance, you can find some more information about it:</p> <p><a href="http://www.javacamp.org/moreclasses/oop/oop5.html" rel="nofollow">http://www.javacamp.org/moreclasses/oop/oop5.html</a></p> <p>Just try to replace <code>extends</code>, <code>implements</code>, <code>with</code> with <code>is a</code> and it becomes more clear. </p> <p>In Scala you also have other variations of <code>is a</code> relation. For example <strong>self types</strong>:</p> <pre><code>trait Bar { self: Foo =&gt; // ... } </code></pre> <p>With this you are saying, that <code>Bar</code> does not extends/implements <code>Foo</code> directly, but all other classes, that want to extend <code>Bar</code> should also extend <code>Foo</code>. </p> <p><strong>Self types</strong> can allow interesting things. For example two classes/traits that depend on each other:</p> <pre><code>class Bar extends Foo { def sayHello(name: String) = println("Hello, " + name) greet() } trait Foo { this: Bar =&gt; def greet() = sayHello("User") } new Bar() // prints: Hello, User </code></pre>
 

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