I am writing a library that provides a distributed algorithm. The idea is that existing applications can add a library to use the algorithm. The algorithm is located in the library module, and it abstracts the actual transmission of data over the network below the line. An application using the algorithm must provide the actual network transport code. In code, it looks something like this:
object Library {
trait RemoteProcess
trait Server {
def send(client: RemoteProcess, msg: String)
}
}
object AkkaDemoApplication {
case class ConcreteRemoteProcess(ref: akka.actor.ActorRef) extends Library.RemoteProcess
class AkkaServer extends Library.Server {
override def send(client: ConcreteRemoteProcess, msg: String): Unit = client.ref ! msg
}
}
A few options that I have considered:
- To have the AkkaServer method signature overload the library method, perform an insecure listing in ConcreteRemoteProcess. Yuk!
- AkkaServer , RemoteProcesss ConcreteRemoteProcess. , , .
- RemoteProcess.
3 :
object Library {
trait Server[RemoteProcess] {
def send(client: RemoteProcess, msg: String)
}
}
object Application {
class AkkaServer extends Library.Server[ActorRef] {
override def send(client: ActorRef, msg: String): Unit = client ! msg
}
}
3, , . , . , , . , , , .
, , , , 2 ( ) " , - ,
- Scala , " ", , ?
. , , , , . , . : , , , , API?