April 2018
Intermediate to advanced
396 pages
11h 8m
English
Now, it's time to see the interesting part representing the previous diagram—the code. As always, we will be going through the individual classes and giving brief explanations where necessary.
The first piece of code that we will look at is the Robot class. We already mentioned that it acts as the receiver and knows how to execute some specific functionality:
case class Robot() { def cleanUp(): Unit = System.out.println("Cleaning up.") def pourJuice(): Unit = System.out.println("Pouring juice.") def makeSandwich(): Unit = System.out.println("Making a sandwich.")}
We've kept the code simple and the methods just print different things to the command line. Next is the robot command with its different implementations:
trait RobotCommand ...Read now
Unlock full access