In my core
sbt module, I have an trait Matrix
for a matrix data type, and a trait MatrixInstance
that has some factory methods. The companion object is supposed to extend this trait.
In a separate sbt submodule implementation1
, I would like to implement this
object Matrix extends MatrixInstance { ... }
companion.
The idea here is that if I decide to have a second implementation, the library user could just change his libraryDependencies += ...
from implementation1
to implementation2
.
However, this doesn't seem to work. i.e. it looks like an object and it's companion must reside in the same module (file?). Otherwise I get circular dependencies and scalac fails.
Is there any pattern I can use to achieve this functionality? i.e. define the interface trait for the factory/companion object, have it implemented in a separate artifact, and then allow the user to choose between the implementations by only changing libraryDependencies
?