この質問は、Akka Concurrencyのプレプリント(最終バージョンはまだ利用できません)に基づいており、説明なしで使用されています。
クラスのバージョン1では、次のようになります。
class Altimeter extends Actor with ActorLogging with EventSource{
...
}
AltimeterはEventSourceと緊密に連携しているため、AltimeterをテストするにはEventSourceもテストする必要があります。修正するための推奨される変更は次のとおりです。
--- a/src/main/scala/Altimeter.scala
+++ b/src/main/scala/Altimeter.scala
@@ -9,9 +9,10 @@ import scala.concurrent.ExecutionContext.Implicits.global
object Altimeter{
case class RateChange(amount: Float) //sent to Altimeter
case class AltitudeUpdate(altitude: Double)
+ def apply() = new Altimeter with ProductionEventSource
}
-class Altimeter extends Actor with ActorLogging with EventSource{
+class Altimeter extends Actor with ActorLogging{ this: EventSource =>
import Altimeter._
val ceiling = 43000 //feet
diff --git a/src/main/scala/EventSource.scala b/src/main/scala/EventSource.scala
index 1fd5578..ded4f38 100755
--- a/src/main/scala/EventSource.scala
+++ b/src/main/scala/EventSource.scala
@@ -8,7 +8,12 @@ object EventSource{
case class UnregisterListener(listener: ActorRef)
}
-trait EventSource { this: Actor =>
+trait EventSource{
+ def sendEvent[T](event: T): Unit
+ def eventSourceReceive: Actor.Receive
+}
+
+trait ProductionEventSource { this: Actor =>
import EventSource._
私の最初の問題は、何がthis: SomeTraitType =>
達成されるのか理解できないことです。クラスはSomeTraitTypeタイプであると文字通り言っていますか?
私の2番目の質問は、それと使用の違いは何extends SomeTraitType
ですか、そしてなぜそれが有利なのですか?前者が意味することを私が知っていれば、おそらくそれは明らかでしょう。