Mobile Architecture Patterns Flashcards
Advantages of a Clean Architecture
Testable
Independent of frameworks
Independent of the UI (UI changes don’t affect others)
Independent of data sources (data sources changes don’t change other layers)
Independent of external elements (business logic is independent of all things around it)
Overview of Apple MVC
View
Sends user action to Controller
Controller
Notifies Model of data updates
Renders updates to the view
Model
Updates data
Sends updates to Controller
Deviates from original MVC in that model updates flow though the Controller (rather than to the view directly)
Describe M (Model) in MVC
Holds the business logic
Access, manipulates, and stores the data
Contains network classes (if needed)
Parses incoming data and converts into model objects
Must not communicate directly with the view (goes through the Controller)
Describe V (View) in MVC
Components that the user can see
These components receive user interactions
Describe C (Controller) in MVC
Main component
Communicates between View and Model
If model data changes, updates the view with changes
Takes care of the application lifecycle
Advantages of MVC architecture
Simple design
Uses less code
Clear separation of responsibilities
Quick development
When to use MVC pattern
simple screens that don’t require complex state & data manipulation
What does MVVM stand for ?
Model - View - ViewModel
4 part design - also a separate VC
Describe V in MVVM
View
- Presents information and responds to user interaction.
- UIKit only accessible from View
- Binds to model using data binding
Describe VM in MVVM
ViewModel - Handles state and prepares data for presentation by the view (ex: formatting date/time strings). Uses delegates to interact with the View
Communicates with Model using observable / data-binding (which requires something like Bond lib or RXSwift (heavy))
Describe M in MVVM
Model - Business logic and responsible for accessing persistent store and networking requests
Communicates with ViewModel using data-binding
Why use MVVM
- More modern design pattern
- Allows better separation of concerns
- Handles complex state management and data manipulation
How would you implement navigation in an MVVM arch ?
Options
1 - ViewModel - trigger the nav and choose where to go. View handles the actual navigation
2 - ViewModel - triggers the navigation. View determines where to go and handles the navigation
3- ViewModel - triggers the navigation. NavCoordinator determines where to go. NavCoordinatior tells view where to go ????
Why is MVVM good for testability ?
State and data manipulation are both in ViewModel. ViewModel can be easily setup and tested without the UI
Ways to handle Dependency Injection
Constructor injection
Setter injection - Property on object sets the value
Method injection - Each function takes a param