I have case classes BFile and AFile that both extend trait File. And case classes BDir and ADir that both extend trait Dir. The classes are instantiated as their trait type.
I am trying to write implicit move methods (located on an object outside the A/BFile and A/BDir classes) that are overloaded for each combination of A/BFile & A/BDir.
I am unsure how to do this such that a different .move method will be implicitly used based on the specific classes of File and Directory. Is this even possible?
The reason why I don't want these methods implemented inside the class is because it requires me to pull in additional dependencies to use the classes; and I am unable to always provide these dependencies.
I also don't want to settle for depending on only the class since I am trying to follow the dependency inversion principle.
Edit: I think I am looking for the following or some equivalent:
trait File {
...
def move(directory: the class implementing this that extends Dir): File
def copy(directory: the class implementing this that extends Dir): File
}
trait Dir {
...
}