I am trying to create a small module system for my application so that I can do this:
new MyApplication extends Module1 with Module2 ... with ModuleN
In order for my modules to register in the application, I also have:
trait ModuleRegistry {
def register(start: () => Unit) =
}
trait Module {
self: ModuleRegistry =>
self.register(start)
def start(): Unit
}
class Application extends ModuleRegistry {
}
trait Module1 extends Module {
...
}
The idea is that modules can register a function with a registry that will be called when the application starts. Unfortunately, the Scala compiler forces me to do this:
trait Module1 extends Module {
self: ModuleRegistry =>
}
means that all implementations of the module should explicitly configure themselves with the registry when, ideally, they do not know about it.
So my questions are:
- ? , "" , . "" , .
- , Scala, ?