Mobile Architecture Patterns Flashcards

1
Q

Advantages of a Clean Architecture

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Overview of Apple MVC

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Describe M (Model) in MVC

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe V (View) in MVC

A

Components that the user can see

These components receive user interactions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Describe C (Controller) in MVC

A

Main component

Communicates between View and Model

If model data changes, updates the view with changes

Takes care of the application lifecycle

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Advantages of MVC architecture

A

Simple design
Uses less code
Clear separation of responsibilities
Quick development

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

When to use MVC pattern

A

simple screens that don’t require complex state & data manipulation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does MVVM stand for ?

A

Model - View - ViewModel

4 part design - also a separate VC

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Describe V in MVVM

A

View
- Presents information and responds to user interaction.
- UIKit only accessible from View
- Binds to model using data binding

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Describe VM in MVVM

A

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))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Describe M in MVVM

A

Model - Business logic and responsible for accessing persistent store and networking requests

Communicates with ViewModel using data-binding

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Why use MVVM

A
  • More modern design pattern
  • Allows better separation of concerns
  • Handles complex state management and data manipulation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How would you implement navigation in an MVVM arch ?

A

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 ????

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Why is MVVM good for testability ?

A

State and data manipulation are both in ViewModel. ViewModel can be easily setup and tested without the UI

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Ways to handle Dependency Injection

A

Constructor injection

Setter injection - Property on object sets the value

Method injection - Each function takes a param

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How is the delegate pattern different from notifications or Combine (SwiftUI ?)

A

Delegates are 1-to-1

Formalized protocol

Can be complex to setup

17
Q

Disadvantages to singleton pattern ?

A
  • Requires global state (hard to track who changes it)
  • Increases coupling
  • Challenges due to multi-threading
18
Q

Ways to make singleton thread safe ?

A

1- Use GCD to require access on main thread

DispatchQueue.global.async() { DispatchQueue.main.async {
MySingleton.shared.doSomething()
} }

2- Make thread-safe using NSLock

19
Q

Describe the MVP pattern

A

Model - View - Presenter

An extension of the Apple MVC pattern where View / VC are merged and Presenter is the intermediary

20
Q

Describe M in MVP pattern

A

Model

  • Handles application data and persistence
21
Q

Describe View in MVP pattern

A

View (and View Controller)

Takes care of UI setup and forwards events to Presenter

22
Q

Describe P in MVP pattern

A

Presenter

The business logic of the application. It formats data for the UI and updates it (through View) using delegate methods.

No UIKit code, so it is easily testable

23
Q

Advantages of MVVM pattern

A

Testability (using mock views)

24
Q

Disadvantages of MVVM pattern

A

Increased complexity due to the need to data binding (which is not a core part of iOS frameworks).