Created
February 4, 2018 19:55
-
-
Save scottroemeschke/01ae8bb1314aee54b2102a85586efa79 to your computer and use it in GitHub Desktop.
very basic example of M in mvp
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 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