Skip to content

Instantly share code, notes, and snippets.

@scottroemeschke
Created February 4, 2018 19:55
Show Gist options
  • Save scottroemeschke/01ae8bb1314aee54b2102a85586efa79 to your computer and use it in GitHub Desktop.
Save scottroemeschke/01ae8bb1314aee54b2102a85586efa79 to your computer and use it in GitHub Desktop.
very basic example of M in mvp
class Calculator {
//obviously a bit silly for a calculator but you get the idea, just think of this as business logic/data/state management
fun add(v1: Int, v2: Int) {
return v1 + v2
}
}
//in this case going to make the presenter stateful, even though in a real apps you shouldn't
class SomePresenter(val calculator: Calculator) {
var currentValue = 0
fun add(value: Int) {
val result = calculator.add(v1,v2)
currentValue = result
view.displayResult(currentValue)
}
interface View {
fun displayResult(result: Int)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment