Created
July 21, 2021 13:05
-
-
Save aasierra/c87b147a391c19efe54208c73b21cef4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* 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