April 2018
Intermediate to advanced
396 pages
11h 8m
English
In the preceding examples, we might quickly run into issues if we have more than one factory method. This would first require the programmer to implement many more methods, but more importantly, it could lead to the returned objects being incompatible. Let's see this in a short example. First, we will declare another trait called SimpleConnectionPrinter, which will have one method that prints something when called:
trait SimpleConnectionPrinter { def printSimpleConnection(connection: SimpleConnection): Unit}
Now, we want to change our DatabaseClient and name it differently (BadDatabaseClient). It will look like the following:
abstract class BadDatabaseClient { def executeQuery(query: String): Unit = { val connection ...
Read now
Unlock full access