Share
Embed
Annual Pro sale · Save $30
Have presentations of your own?
Share with private links, password protection, and more control over your work.
Transcript
95 slides
-
≥ Activity / Fragment View models View Domain Presenter /
ViewModel Use Case Use Case … -
≥ Activity / Fragment Use Case Use Case … View
models View Domain Presenter / ViewModel Entities -
≥ Activity / Fragment Use Case Use Case … Entities
View models View Domain Presenter / ViewModel Mapper -
≥ Activity / Fragment Use Case Use Case … Entities
View models Mapper View Domain Presenter / ViewModel Repository … Repository -
≥ Activity / Fragment Use Case Use Case … Repository
Entities … View models Mapper View Domain Repository Presenter / ViewModel Data -
≥ Activity / Fragment Use Case Use Case … Repository
Entities … View models Mapper View Domain Data Repository Presenter / ViewModel Repository Impl Repository Impl -
≥ Activity / Fragment Use Case Use Case … Repository
Entities … View models Mapper View Domain Data Repository Repository Impl Repository Impl Presenter / ViewModel Data Source … Data Source -
≥ Activity / Fragment Use Case Use Case … Repository
Data Source … Data Source Entities … View models Mapper View Domain Data Repository Repository Impl Repository Impl Presenter / ViewModel Database Remote API -
≥ Activity / Fragment Use Case Use Case … Repository
Data Source … Data Source Entities … View models Mapper Database Remote API View Domain Data Repository Repository Impl Repository Impl Presenter / ViewModel Data models -
≥ Activity / Fragment Use Case Use Case … Repository
Data Source … Data Source Entities … Data models View models Mapper Database Remote API View Domain Data Repository Repository Impl Repository Impl Presenter / ViewModel Mapper -
≥ Activity / Fragment Use Case Use Case … Repository
Data Source … Data Source Entities … Data models View models Mapper Mapper Database Remote API View Domain Data Repository Repository Impl Repository Impl Presenter / ViewModel -
≥ Activity / Fragment Use Case Use Case … Repository
Data Source … Data Source Entities … Data models View models Mapper Mapper Database Remote API View Domain Data Repository Repository Impl Repository Impl Presenter / ViewModel -
≥ Activity / Fragment Use Case Use Case … Repository
Data Source … Data Source … Data models View models Mapper Mapper Database Remote API View Domain Data Repository Repository Impl Repository Impl Presenter / ViewModel Entities -
≥ Activity / Fragment … Repository Data Source … Data
Source Entities … Data models View models Mapper Mapper Database Remote API View Domain Data Repository Repository Impl Repository Impl Presenter / ViewModel Use Case Use Case -
≥ Activity / Fragment Use Case Use Case … Repository
… Entities … Data models View models Mapper Mapper Database Remote API View Domain Data Repository Repository Impl Repository Impl Data Source Data Source Presenter / ViewModel -
≥ Use Case Use Case … Repository Data Source …
Data Source Entities … Data models View models Mapper Mapper View Domain Data Repository Repository Impl Repository Impl Presenter / ViewModel Activity / Fragment Database Remote API -
≥ “Typically the data that crosses the boundaries is simple
data structures. You can use basic structs or simple Data Transfer objects if you like […] We don’t want to cheat and pass Entities or Database rows. ” -
≥ Activity / Fragment Use Case Use Case … Repository
Data Source … Data Source Entities … Database Remote API View Domain Data Repository Repository Impl Repository Impl Presenter / ViewModel Data models View models Mapper Mapper -
≥ Activity / Fragment Use Case Use Case … Repository
Data Source … Data Source Entities … Data models View models Mapper Mapper Database Remote API View Domain Data Repository Repository Impl Repository Impl Presenter / ViewModel -
≥ Activity / Fragment Use Case Use Case … Data
Source … Data Source Entities … Data models View models Mapper Mapper Database Remote API View Domain Data Presenter / ViewModel Repository Repository Repository Impl Repository Impl -
≥ “[…] use cases orchestrate the flow of data to
and from the entities, and direct those entities to use their enterprise wide business rules to achieve the goals of the use case.” -
≥ Activity / Fragment Use Case Use Case … Repository
Data Source … Data Source Entities … Data models View models Mapper Mapper Database Remote API View Domain Data Repository Repository Impl Repository Impl Presenter / ViewModel -
≥ Activity / Fragment Use Case Use Case … Data
Source … Data Source Entities Data models View models Mapper Mapper Database Remote API View Domain Data Presenter / ViewModel -
≥ Activity / Fragment Use Case Use Case … Repository
Data Source … Data Source Entities … Data models View models Mapper Mapper Database Remote API View Domain Data Repository Repository Impl Repository Impl Presenter / ViewModel -
≥ Activity / Fragment Use Case Use Case … Repository
Data Source … Data Source Entities … Data models View models Mapper Mapper Database Remote API View Domain Data Repository Repository Impl Repository Impl Presenter / ViewModel -
≥ Activity / Fragment Use Case Use Case … Repository
Data Source Impl … Data Source Impl Entities … Data models View models Mapper Mapper Database Remote API View Domain Data Repository Data Source Data Source Presenter / ViewModel -
≥ Activity / Fragment Use Case Use Case … Repository
Entities … Data models View models Mapper Mapper Database Remote API View Domain Data Repository … Data Source Impl Data Source Impl Data Source Data Source Presenter / ViewModel -
≥ “[…] a set of adapters that convert data from
the format most convenient for the use cases and entities, to the format most convenient for some external agency such as the Database” -
≥ Activity / Fragment Use Case Use Case … Repository
Data Source Impl Data Source Impl Entities … Data models View models Mapper Mapper Database Remote API View Domain Data Repository Data Source Data Source Presenter / ViewModel … -
≥ Activity / Fragment Use Case Use Case … Repository
Entities … Data models View models Mapper Mapper Database Remote API View Domain Data Repository … Adapter Impl Adapter Impl Adapter Interface Adapter Interface Adapter -
≥ Activity / Fragment Use Case Use Case … Repository
Adapter Impl Adapter Impl Entities … Data models View models Mapper Mapper Database Remote API View Domain Data Repository Adapter Interface Adapter Interface Adapter … -
≥ Activity / Fragment Use Case Use Case … Repository
Adapter Impl Adapter Impl Entities … Data models View models Mapper Mapper Database Remote API View Domain Data Repository Adapter Interface Adapter Interface Adapter … -
≥ Activity / Fragment Use Case Use Case … Repository
Adapter Impl Adapter Impl Entities … Data models View models Mapper Mapper Database Remote API Frameworks Enterprise business rules Frameworks Repository Adapter Interface Adapter Interface Adapter Application business rules … -
≥ Activity / Fragment Use Case Use Case … Repository
Adapter Impl … Adapter Impl Entities … Data models View models Mapper Mapper Database Remote API Frameworks Enterprise business rules Frameworks Repository Adapter Interface Adapter Interface Adapter Application business rules -
≥ Activity / Fragment Use Case Use Case … Repository
Adapter Impl Adapter Impl Entities … Data models View models Mapper Mapper Database Remote API Frameworks Frameworks Repository Adapter Interface Adapter Interface Adapter Application business rules … Domain -
≥ Activity / Fragment Use Case Use Case … Repository
Adapter Impl Adapter Impl Entities … Data models View models Mapper Mapper Database Remote API Domain Repository Adapter Interface Adapter Interface Adapter Application business rules … UI Storage Remote -
≥ Activity / Fragment Use Case Use Case … Repository
Adapter Impl Adapter Impl Entities … Data models View models Mapper Mapper Database Remote API UI Domain Storage Repository Adapter Interface Adapter Interface Adapter … Remote N x Feature business rules -
≥ Activity / Fragment Use Case Use Case … Repository
Adapter Impl Adapter Impl Entities … Data models View models Mapper Mapper Database Remote API UI Domain Storage Repository Adapter Interface Adapter Interface N x Feature business rules … Remote Adapter -
≥ Activity / Fragment Use Case Use Case … Repository
Adapter Impl Adapter Impl Entities … Data models View models Mapper Mapper Database Remote API UI Domain Storage Repository Adapter Interface Adapter Interface N x Feature business rules … Remote Presenter -
≥ Activity / Fragment Use Case Use Case … Repository
Adapter Impl Adapter Impl Entities … Data models View models Mapper Mapper Database Remote API UI Domain Storage Repository Adapter Interface Adapter Interface N x Feature business rules … Remote Presenter -
≥ Activity / Fragment Use Case Use Case … Repository
Adapter Impl Adapter Impl Entities … Data models Mapper Database Remote API Domain Storage Repository Adapter Interface Adapter Interface Presenter N x Feature business rules … Remote View Interface UI -
≥ Use Case Use Case … Repository … Repository Adapter
Interface Adapter Interface Presenter N x Feature business rules … Activity / Fragment Adapter Impl Adapter Impl Entities Data models Mapper Database Remote API Domain Storage Remote UI View Interface -
≥ Use Case Use Case … Repository … Repository Adapter
Interface Adapter Interface Presenter N x Feature business rules … View Interface -
≥ Use Case Use Case … Repository … Repository Adapter
Interface Adapter Interface Presenter N x Feature business rules … View Interface Activity / Fragment Adapter Impl Adapter Impl Entities Data models Mapper Database Remote API Domain Storage Remote UI -
≥ Use Case Repository Adapter Interface Adapter Interface Presenter N
x Feature business rules … View Interface Activity / Fragment Adapter Impl Adapter Impl Entities Data models Mapper Database Remote API Domain Storage Remote UI -
≥ Use Case Repository Adapter Interface Adapter Interface Presenter N
x Feature business rules … State View Interface Activity / Fragment Adapter Impl Adapter Impl Entities Data models Mapper Database Remote API Domain Storage Remote UI -
≥ sealed class State<out T : Any> class Loaded<out T
: Any>(val data: T) : State<T>() class Loading() : State<Nothing>() class Error(val message: String) : State<Nothing>() -
≥ fun loadProduct(productId: String) { val productDetailsState = getProductDetails.execute(productId) when(productDetailsState)
{ is Error -> view.renderDetailsError(productDetailsState.message) is Loading -> view.renderLoading() is Loaded -> view.renderDetails(productDetailsState.data) } } -
≥ fun onPhoneNumberVerification(phoneNumber: String) { val result = checkPhoneNumber.execute(phoneNumber) result.fold({
view.renderGenericError }, { checkPhoneState(it) }) } private fun checkPhoneState(state: VerificationState) { when (state) { is Invalid -> view.renderInvalidError() is ExhaustedAttempts -> view.renderExhaustedAttempts(state.code) is Verified -> view.navigateToSuccess() } } -
≥ fun onPhoneNumberVerification(phoneNumber: String) { val result = checkPhoneNumber.execute(phoneNumber) result.fold({
view.renderGenericError }, { checkPhoneState(it) }) } private fun checkPhoneState(state: VerificationState) { when (state) { is Invalid -> view.renderInvalidError() is ExhaustedAttempts -> view.renderExhaustedAttempts(state.code) is Verified -> view.navigateToSuccess() } } -
≥ Activity / Fragment Use Case Adapter Impl Adapter Impl
Entities Data models Mapper Database Remote API UI Domain Storage Repository Adapter Interface Adapter Interface Presenter N x Feature business rules … Remote State View Interface -
≥ Activity / Fragment Use Case Adapter Impl Adapter Impl
Data models Mapper Database Remote API UI Domain Storage Repository Adapter Interface Adapter Interface N x Feature business rules … Remote State View Interface Entities Presenter -
≥ Use Case Adapter Impl Adapter Impl Data models Mapper
Database Remote API UI Domain Storage Repository Adapter Interface Adapter Interface N x Feature business rules … Remote State View Interface Activity / Fragment Entities Presenter -
≥ Use Case Adapter Impl Adapter Impl Data models Mapper
Database Remote API UI Domain Storage Repository Adapter Interface Adapter Interface N x Feature business rules … Remote State View Interface Activity / Fragment Presenter Entities -
≥ class Product( val id: String, val name: String, val
price: String, val image: String, val description: String, val distanceInMeters: Int ) Domain module UI module internal fun Product.getPriceInEuros() = "$price €" -
≥ Activity / Fragment Use Case Adapter Impl Adapter Impl
Entities Data models Mapper Database Remote API UI Domain Storage Repository Adapter Interface Adapter Interface Presenter N x Feature business rules … Remote State View Interface -
≥ Different asynchronous approaches •Use Case executed inside a ThreadPoolExecutor
•Presenter subscribes to a Use Case (RxJava) •Coroutines for a “synchronous” code -
≥ class PhoneVerificationPresenter( private val checkVerificationStatus: CheckVerificationStatusUseCase, ) { //…
fun onViewLoaded() { launch(UI) { val state = async { checkVerificationStatus.execute() }.await() checkVerificationState(state) } } //… -
≥ class PhoneVerificationPresenter( private val checkVerificationStatus: CheckVerificationStatusUseCase, ) { //…
fun onViewLoaded() { launch(UI) { val state = async { checkVerificationStatus.execute() }.await() checkVerificationState(state) } } //… -
≥ class PhoneVerificationPresenter( private val checkVerificationStatus: CheckVerificationStatusUseCase, ) { //…
fun onViewLoaded() { launch(mainContext) { val state = async(backgroundContext) { checkVerificationStatus.execute() }.await() checkVerificationState(state) } } //… -
≥ object CoroutineContexts { lateinit var mainContext: CoroutineContext lateinit var
backgroundContext: CoroutineContext } -
≥ public class Application extends android.app.Application { //… private void
setCorutineContexts() { CoroutineContexts.mainContext = WallapopContexts.getMain(); CoroutineContexts.backgroundContext = WallapopContexts.getBackground(); } //… } -
≥ var WALLAPOP_MAIN: CoroutineContext = UI var WALLAPOP_BG: CoroutineContext =
newFixedThreadPoolContext(2 * Runtime.getRuntime().availableProcessors(), "bg") object WallapopContexts { @JvmStatic var main = WALLAPOP_MAIN @JvmStatic var background = WALLAPOP_BG } -
≥ @Test fun `render verification code when status is Verified`()
{ whenever(checkStatus.execute()).doReturn(Verified()) presenter.onViewLoaded() verify(view).renderSuccess() } -
≥ abstract class UnitTest { init { CoroutineContexts.mainContext = CoroutineContextForTest
CoroutineContexts.backgroundContext = CoroutineContextForTest } } -
≥ object CoroutineContextForTest : CoroutineDispatcher() { override fun dispatch(context: CoroutineContext,
block: Runnable) { block.run() } } -
≥ Given a team… •The app you have to develop
•The problems you have to solve •The rules you have to follow •The trade offs you have to evaluate •The agreements you decide to take