Skip to content

Instantly share code, notes, and snippets.

@fbcbl
Last active October 9, 2017 12:24
Show Gist options
  • Save fbcbl/6313c84646eb5348d96c22334a61ba9f to your computer and use it in GitHub Desktop.
Save fbcbl/6313c84646eb5348d96c22334a61ba9f to your computer and use it in GitHub Desktop.
kotlin_testing_pt2_example_2
class Coordinate(latitude: Double, longitude: Double)
interface LocationProvider {
fun getLastKnownLocation(): Coordinate
fun getExactLocation(): Coordinate
}
interface TemperatureProvider {
fun getCelsiusTemperatureAt(coordinate: Coordinate): Float
}
interface View {
fun displayTemperature(temperature: Float)
}
class TemperaturePresenter(
private val locationProvider: LocationProvider,
private val temperatureProvider: TemperatureProvider,
private val view: View) {
fun start() {
val lastLocation = locationProvider.getLastKnownLocation()
val inaccurateTemperature =
temperatureProvider.getCelsiusTemperatureAt(lastLocation)
view.displayTemperature(inaccurateTemperature)
val exactLocation = locationProvider.getExactLocation()
val accurateTemperature =
temperatureProvider.getCelsiusTemperatureAt(exactLocation)
view.displayTemperature(accurateTemperature)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment