For the code example, in this chapter, let's build a simple Quote of the Day service that returns a quote based on the day of the year. Since we might have fewer quotes in our store, the service should repeat the quotes in a cyclic fashion. Again, as usual, we will try to keep it as simple as possible to focus more on build aspects rather than the application logic. We will create two separate Gradle projects to implement the exact same functionality, once in Groovy then in Scala.
Before going into language-specific details, let's start with defining the QotdService
interface, which just declares only one method, getQuote
. The contract is, as long as we pass the same date, we should get the same quote back:
package com.packtpub.ge.qotd; import java.util.Date; interface QotdService { String getQuote(Date day); }
The logic to implement getQuote
can use the Date
object in any manner, such as using the entire date including the time for determining the quote. However...