The purpose of this article is to mainly illustrate these two things: (1) That Scala can be gradually introduced into your project/organization because of the nice interopability with Java (in this code below, there is very little Scala code, but only some Scala implementations of a Java interface) (2) That you can implement an interface for a specific instance, without having to create a class that implements the interface
The initial scenario is that we have some duplicated code which you want to refactor away, but with Java you will need to write a bit more code that you would like to, while the Scala solution is a bit shorter. In the class below, there are two methods that contain exactly the same implementation, but they have different parameters. One of the method receives an instance of the class RandomAccessFile, while the other receives an instance of BufferedReader. It is very important to note that these two classes do NOT ( ! ) share a common base type (except Object) that contains the only used method 'readLine', because if there were such a bae type, then we would be done by simply removing one of the methods, and change the formal parameter type to that common base type with the mehod 'readLine'.