Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aasierra/c87b147a391c19efe54208c73b21cef4 to your computer and use it in GitHub Desktop.
Save aasierra/c87b147a391c19efe54208c73b21cef4 to your computer and use it in GitHub Desktop.
/**
* Business logic center.
*/
class ProductInfoBusinessLogicCenterViewModel: ViewModel() {
/**
* Observable object for the view to watch.
*/
val productInfo = MutableLiveData<ProductInfoDisplay>()
init {
/**
* Creating a fake server response. Something like this would normally come back from
* Retrofit or a repository of data.
*/
val fakeServerResponseObject = ServerObject(ServerProductInformation("Product Name", "$1,000,000", true))
/**
* Business Logic that belongs in the BusinessLogicCenter
*/
val price = if (fakeServerResponseObject.product.isOnSale) {
"See Website"
} else {
fakeServerResponseObject.product.price
}
/**
* Grabbing only what the view needs to know about from the response.
*/
productInfo.value = ProductInfoDisplay(fakeServerResponseObject.product.productName, price)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment