<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Schauderhaft &#187; trait</title>
	<atom:link href="http://blog.schauderhaft.de/tag/trait/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.schauderhaft.de</link>
	<description>Softwaredevelopment, Projectmanagement, Qualitymanagement and all things &#34;schauderhaft&#34;</description>
	<lastBuildDate>Sun, 05 Feb 2012 20:46:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Ratchet Tests with ScalaTest</title>
		<link>http://blog.schauderhaft.de/2011/09/18/ratchet-tests-with-scalatest/</link>
		<comments>http://blog.schauderhaft.de/2011/09/18/ratchet-tests-with-scalatest/#comments</comments>
		<pubDate>Sun, 18 Sep 2011 04:17:21 +0000</pubDate>
		<dc:creator>Jens Schauder</dc:creator>
				<category><![CDATA[Softwaredevelopment]]></category>
		<category><![CDATA[scalatest]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[trait]]></category>

		<guid isPermaLink="false">http://blog.schauderhaft.de/?p=926</guid>
		<description><![CDATA[Ever found more broken things in a project than you possible could fix in one go? I&#8217;m exactly in that situation. We have a test which checks for certain dependencies in our project. The problem: We discovered that the test was broken and didn&#8217;t report all disallowed dependencies. We do know how to fix it, [...]]]></description>
			<content:encoded><![CDATA[<p>Ever found more broken things in a project than you possible could fix in one go? I&#8217;m exactly in that situation. We have a test which checks for certain dependencies in our project. The problem: We discovered that the test was broken and didn&#8217;t report all disallowed dependencies. We do know how to fix it, but if we do it will fail. And since there are many violations it will take quite some time to fix all of them. But of course we want to prevent even more violations of our dependency rules. </p>
<p>The solution could be a ratchet on the tests. A contraption which accepts broken tests, but which doesn&#8217;t allow tests to fail once they succeeded.</p>
<p>For ScalaTest you can create appropriate tests using this simple <tt>Ratchet</tt> trait</p>
<div class="geshi no scala">
<ol>
<li class="li1">
<div class="de1">package de.schauderhaft.ratchet
</div>
</li>
<li class="li1">
<div class="de1">import org.scalatest.AbstractSuite
</div>
</li>
<li class="li1">
<div class="de1">import org.scalatest.Suite
</div>
</li>
<li class="li1">
<div class="de1">import org.scalatest.TestFailedException
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">trait Ratchet extends AbstractSuite {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; self : Suite =&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; private var tests = Set[String]()
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; def ratchet(ratchetedTests : Set[String]) {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; tests = ratchetedTests
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; }
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; override abstract def withFixture(theTest : NoArgTest) {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; if (tests.contains(theTest.name)) {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var failedToFail = false
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; super.withFixture(theTest)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; failedToFail = true
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } catch {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case ex : TestFailedException =&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (failedToFail)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fail(&quot;Remove &#39;%s&#39; from the ratchet it doesn&#39;t fail anymore&quot;.format(theTest.name))
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; } else
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; super.withFixture(theTest)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; }
</div>
</li>
<li class="li1">
<div class="de1">}</div>
</li>
</ol>
</div>
<p>It adds a <tt>ratchet</tt> method to your suite. You pass it a <tt>Set</tt> of test names. These are the tests that you expect to fail. If they do fail, the <tt>Ratchet</tt> will convert that failure to a success. If a test which you expect to fail succeeds, the <tt>Ratchet</tt> will make sure it does fail with a message saying you should remove it from the tests expected to fail. Tests not registered with the <tt>ratchet</tt> method behave just as normal tests do. This is how the contraption looks in action with an example test suite: (Note tests which start witch &#8216;expected:&#8217; do fail</p>
<div class="geshi no scala">
<ol>
<li class="li1">
<div class="de1">class RatchetTestDemo extends FunSuite with ShouldMatchers with Ratchet {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; ratchet(Set(
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &quot;a failing test with ratchet does not fail&quot;,
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &quot;expected: a succeeding test with ratchet fails&quot;))
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; test(&quot;a failing test with ratchet does not fail&quot;) {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; fail
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; }
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; test(&quot;expected: a failing test without ratchet fails&quot;) {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; fail
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; }
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; test(&quot;a succeeding test without ratchet succeeds&quot;) {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; }
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; test(&quot;expected: a succeeding test with ratchet fails&quot;) {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; println(&quot;hallo&quot;)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; }
</div>
</li>
<li class="li1">
<div class="de1">}</div>
</li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.schauderhaft.de/2011/09/18/ratchet-tests-with-scalatest/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Usage Patterns of Scala Traits</title>
		<link>http://blog.schauderhaft.de/2011/08/21/usage-patterns-of-scala-traits/</link>
		<comments>http://blog.schauderhaft.de/2011/08/21/usage-patterns-of-scala-traits/#comments</comments>
		<pubDate>Sun, 21 Aug 2011 11:28:10 +0000</pubDate>
		<dc:creator>Jens Schauder</dc:creator>
				<category><![CDATA[Softwaredevelopment]]></category>
		<category><![CDATA[pattern]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[trait]]></category>

		<guid isPermaLink="false">http://blog.schauderhaft.de/?p=901</guid>
		<description><![CDATA[One of the many cool features in Scala are traits. traits are like a mixture of abstract classes and interfaces: You can &#8216;implement&#8217; as many of them as you want just as with interfaces, but they can also contain implementation, which makes them similar to abstract classes. You also can&#8217;t instantiate a trait on its [...]]]></description>
			<content:encoded><![CDATA[<p>One of the many cool features in Scala are traits. traits are like a mixture of abstract classes and interfaces: You can &#8216;implement&#8217; as many of them as you want just as with interfaces, but they can also contain implementation, which makes them similar to abstract classes. You also can&#8217;t instantiate a trait on its own, so there is another similarity to abstract classes.</p>
<p>While digging my way through various libraries I found a couple of different usage patterns, how traits are getting used. Here is what I found so far:</p>
<div><strong>The Introvert Trait</strong>: These are traits that aren&#8217;t intended for changing the behavior of a class for outside clients of the class, but for the code inside the class itself. They often make an internal DSL available. An example are the <a href="http://www.scalatest.org/scaladoc-1.6.1/#org.scalatest.matchers.ShouldMatchers">ShouldMatchers</a> in <a href="http://www.scalatest.org/">ScalaTest</a>. You mix in this trait into your test class in order to use syntax like <tt>someValueToTest should be (23)</tt> The problem with this kind of usage is that you can&#8217;t really control the scope in which your trait/DSL applies. So if you want to use two such traits which happen do define the same method or operator with different meaning you are in trouble. Often you can replace the trait with an object which you import. Since scoping rules apply for imports as well you can control much better which part of your class have access to that object. I see two reasons why this kind of trait makes sense: It makes the presence of the trait/DSL very obvious since it is right next in the beginning of the class declaration, while an import statement might get overlooked. The other reason is, if you want to fool around with <a href="http://www.scala-lang.org/node/124">self types</a>, i.e. you want to limit the kind of classes the trait can get mixed in to or if you want to reference that class.</div>
<div><strong>Classes with dissociative identity disorder:</strong> Sometimes things are two things at once. A wooden chair might be furniture as well as fuel for an oven. A square is a rectangle and a rhombus. This works perfectly with traits. While in java you would often have two interface, but one class implementing both, you can easily split the implementation between two traits in scala. Nice. But you should carefully check if these two behaviors  actually belong in a single class, or if you are violating the <a href="http://en.wikipedia.org/wiki/Single_responsibility_principle">Single Responsibility Principle</a>.<br />
<strong></strong></div>
<div><strong>The Jigsaw Puzzle Trait:</strong> In this pattern traits are used to separate different aspects of a responsibility in a very fine grained manner. The results are traits that are really hard to understand on their own. Actually they are easy to understand since the often only consist of half a dozen lines of code. What is difficult is to understand how this can be useful in any way. Yet if done right it allows do reduce code duplication to an absolute minimum. The best example for this usage is the <a href="/2010/12/19/the-scala-collection-api-sucks-or-is-it-a-work-of-beauty/">Scala collection API</a>. It consists of a huge number of traits, that get assembled in different ways in order to form the different classes.<br />
<strong>The Steam Roller Trait</strong>: What happens when you drive a steam roller over something small, let&#8217;s say an interface? It gets very wide. This is another technique used in the Scala Collection API. The trait defines a self type, either using another trait or a structural type and defines lots of other stuff based on that interface. This completely solves one of the basic challenges in Java interface design: If you define wide interfaces, i.e. interfaces with lots of methods, it increases the chances for users to find the method they need. On the other hand those poor bastards who have to implement such an interface have a lot of work to do. If you have any doubts how powerful this pattern is, check out <a href="http://www.scala-lang.org/docu/files/collections-api/collections-impl.html">how little code you have to write</a> in order to create a new collection implementation which nicely integrates with all the others and has hundreds of methods just like all the other Scala collections as well.</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.schauderhaft.de/2011/08/21/usage-patterns-of-scala-traits/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mixins, Inheritance and Delegation</title>
		<link>http://blog.schauderhaft.de/2010/01/24/mixin-inheritance-delegation/</link>
		<comments>http://blog.schauderhaft.de/2010/01/24/mixin-inheritance-delegation/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 11:27:49 +0000</pubDate>
		<dc:creator>Jens Schauder</dc:creator>
				<category><![CDATA[Softwaredevelopment]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[delegate]]></category>
		<category><![CDATA[inheritance]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[mixin]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[trait]]></category>

		<guid isPermaLink="false">http://blog.schauderhaft.de/?p=385</guid>
		<description><![CDATA[A week ago I started learning Scala. One of the features I found pretty interesting are mixins and traits. That was just the point of time, when I read this little tweet of GeekyL: &#8220;i am still not sure if mixins are super cool or dark magic.&#8221; Of course I was instantly reminded of the [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_391" class="wp-caption alignright" style="width: 310px"><a href="http://blog.schauderhaft.de/wp-content/uploads/2010/01/962589_79025341x.jpg"><img class="size-medium wp-image-391" title="962589_79025341x" src="http://blog.schauderhaft.de/wp-content/uploads/2010/01/962589_79025341x-300x299.jpg" alt="Blender" width="300" height="299" /></a><p class="wp-caption-text">Blender</p></div>
<p>A week ago I started learning <a href="http://www.scala-lang.org/">Scala</a>. One of the features I found pretty interesting are <a href="http://www.scala-lang.org/node/117">mixins and traits</a>. That was just the point of time, when I read this little <a href="http://twitter.com/GeekyL/status/8037135496">tweet</a> of <a href="http://twitter.com/GeekyL">GeekyL</a>:</p>
<p>&#8220;i am still not sure if mixins are super cool or dark magic.&#8221;</p>
<p>Of course I was instantly reminded of the time when the dinosaurs dominated the world and I was learning the first little bits of OO and C++. I thought inheritance and polymorphism was great and the solution for every possible programming problem there is. It turned out that was not the case. Actually inheritance can result in pretty ugly code.</p>
<p>So GeekyL&#8217;s tweet got me thinking: Do mixins have the same problem? What exactly are the problems with inheritance anyway? Time for a new blog post.</p>
<p><strong>What are the problems of inheritance?</strong></p>
<p><strong>Inheritance for code reuse</strong>: It is tempting to have a class inherit from a superclass just because the superclass has some useful feature. Like this.</p>
<div class="geshi no java">
<div class="head">import java.beans.PropertyChangeSupport;</div>
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">public</span> <span class="kw2">class</span> PropertySupport <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">protected</span> <span class="kw3">PropertyChangeSupport</span> propSup<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">public</span> <span class="kw2">class</span> UserEntity <span class="kw2">extends</span> PropertySupport <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">private</span> <span class="kw3">String</span> firstName<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">public</span> <span class="kw4">void</span> setFirstName<span class="br0">&#40;</span><span class="kw3">String</span> aFirstName<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw3">String</span> oldValue = firstName<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; firstName = aFirstName<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; propSup.<span class="me1">firePropertyChange</span><span class="br0">&#40;</span><span class="st0">&quot;firstName&quot;</span>, oldValue, firstName<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>The problem with such code is that inheritance suggests a is-a-relationship, which in this case is just wrong. A UserEntity is not a PropertySupport, it just uses one.</p>
<p><strong>Multiple inheritance</strong>: At least in java a class can only inherit from one superclass. But many classes are many things. For example, a Cat is a Carnivor, it is a FourLeggedAnimal and a FurryAnimal. Without multiple inheritance there is just no way how to model this with class inheritance. With multple inheritance you can extend all these classes at the same time, but now you inherit the top class Animal three times, which at least is ugly.</p>
<p>So the proper way to do this kind of stuff in java is to use delegation and interfaces:</p>
<div class="geshi no java">
<div class="head">public class Cat implements Furry, FourLegged {</div>
<ol>
<li class="li1">
<div class="de1">&nbsp;FurryDelegate fd<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;FourLeggedDelegate fld<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;@Override</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">public</span> <span class="kw4">void</span> pet<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; fd.<span class="me1">pet</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;@Override</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">public</span> <span class="kw4">void</span> runFast<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; fld.<span class="me1">runFast</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Which works in the sense that you can pretty much express the kind of things you need to do, and which you might be tempted to solve with class inheritance. Of course the draw back is that you&#8217;ll have to create all theses trivial delegate methods.</p>
<p>In Scala you have the option to use Traits. Like so</p>
<div class="geshi no scala">
<div class="head">class Animal</div>
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">class Cat extends Animal with Furry with FourLegs{
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">}
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">trait Furry{
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;def pet() {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; println(&quot;purrrrr&quot;)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;}
</div>
</li>
<li class="li1">
<div class="de1">}
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">trait FourLegs{
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;def runFast() {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; println(&quot;I&#39;m gone&quot;)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;}
</div>
</li>
<li class="li1">
<div class="de1">}</div>
</li>
</ol>
</div>
<p>Obviously this contains much less code duplication then the java version. Does it have drawbacks? You bet.</p>
<p>Mixins are firmly tied to the traits they use. Imagine a more complex trait, which itself uses many other clases and resources. Once you mix in such a trait you have a strong dependency. Therefor I suggest the following pattern for getting the reduction of code duplication from traits and the flexibility of delegates: Use Traits, which don&#8217;t have a real implementation, but use a delegate for doing all the real stuff, this way you can switch the implementation with touching just a single place:</p>
<div class="geshi no scala">
<div class="head">class Superclass</div>
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">class Mixin extends Superclass with Trait {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; // &#8230; more stuff goes here
</div>
</li>
<li class="li1">
<div class="de1">}
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">trait Trait {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; val delegate = new TraitImpl // this should be some kind of DI or lookup in a real system
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; def aMethod() {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; delegate.aMethod()
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; }
</div>
</li>
<li class="li1">
<div class="de1">}
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">class TraitImpl extends Trait {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; override def aMethod(){
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; println(&quot;you just called me&quot;)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; }
</div>
</li>
<li class="li1">
<div class="de1">}</div>
</li>
</ol>
</div>
<p>Summary: Traits can be used to solve some of the problems of inheritance, but they might introduce strong coupling, which you can easily be avoided.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.schauderhaft.de/2010/01/24/mixin-inheritance-delegation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

