Last active
October 9, 2017 12:24
-
-
Save fbcbl/6313c84646eb5348d96c22334a61ba9f to your computer and use it in GitHub Desktop.
kotlin_testing_pt2_example_2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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