20180730 iOS MVVM Discussion (pt. 2)
Action items from our last meeting on Jul. 27:
- Bobby's A/B testing case in Accommodation
- Improve testability in approach 2
- Discuss other possible scenarios that may involve VM and/or VC reuse or subclassing.
- Finalize on which approach we should go with.
What did we discuss?
- We discussed about Approach 3, which introduces the
Interactor
object to purely handle business logic and communicate with the View Model
. The View Model still controls the UI behavior (i.e. what to do when a button is tapped).
- We discussed about the flexibility of approach 3; depending on respective team's cost/benefit analysis for the implementation, they can either choose to implement this partially – but the goal is that even with partial implementation, it still falls under the same definition.
- In accom's case, the View Model role can be merged with View Controller, and the VC communicates directly with the Interactor (basically approach 2).
- Or the other way is to merge the View Model with the Interactor, behaving similarly like Approach 1.
- My suggestion is to standardize the implementation either per mission, or per evangelist group.
- We discussed about how approach 3 would work in cases such as:
- A/B testing (Accom's case)
- View containment (e.g. Flight + Hotel homepage)
- Page reuse (e.g. Change hotel in Trip booking, reusing Hotel search result)
- We also discussed about lifecycle forwarding to View Model, and agreed that it's a bad practice. Instead, we will let the VC to call contextual actions – the reasoning is that each page is consistent with its purpose despite it having subclasses.
- For example, search result page's purpose is to display a list of data. Even if it is subclassed and overridden, the purpose stays the same. Therefore, it does make sense for the View Controller to have access to
loadData
on the view model.
What have we agreed on?
- We agreed that approach 3 is the way to go, but we still need to gather concerns from other iOS engineers on other possible case studies.
- We agreed that in approach 3, we don't have to "forward" lifecycle events. Instead, we let the VC to call "contextual actions".
What's next?
- Evangelists will try to gather concerns from their respective groups regarding adoption of Approach 3 within this week.
- We will discuss additional concerns from iOS engineers if any, and formalize the standard on our meeting this Friday.
- I will start formalizing the approach 3 definition and have it ready before evangelist meeting this Friday.
Resources