Architecture foundations interview lab
Rapid answers
MVVM versus MVI?
MVVM describes UI–ViewModel roles; MVI usually emphasizes explicit intents, immutable state, and reducer-like transitions. They can coexist. Explain concrete ownership and flow rather than treating labels as mutually exclusive.
Does Clean Architecture require a domain layer?
No fixed Android template is universal. Protect stable business policy with inward dependencies; add a domain layer when complexity, reuse, volatility, or ownership makes it valuable.
Why repository?
It owns application-data policy: exposes data, centralizes mutation, abstracts sources, and can resolve cache/network conflicts. A class that merely renames one DAO call may not yet provide that value.
Case study: offline order submission
Requirements: edit cart offline, submit exactly once, resume after process death, server may reject price changes.
- Room is local source of truth for cart/order attempt.
- Repository transaction creates submission with stable idempotency key.
- Use case validates reusable business rules and requests submission.
- Worker retries eligible attempts using the same key.
- Server response maps to durable Accepted/Rejected state.
- ViewModel observes repository and derives UI state.
- UI emits intents and never assumes a snackbar means success.
Tradeoffs: stronger consistency and recovery require schema/state-machine complexity; payment/order truth justifies it.
Architecture review questions
- What changes together, and who owns it?
- Where is the source of truth?
- Which transitions are impossible by type?
- What happens on retry, cancellation, duplicate input, and process death?
- Which framework types cross boundaries?
- Do fakes honor production behavior?
- Which layer can be removed without losing a property?
- How will dependency direction be enforced?
Practical mistakes
- ❌ One ViewModel per reusable composable regardless of lifecycle/logic.
- ✅ ViewModel for screen business state; local/plain holder for UI mechanics.
- ❌ Interface and mapper for every class because “Clean.”
- ✅ Boundaries follow volatility, ownership, and contracts.
- ❌
MutableStateFlowexposed publicly. - ✅ Immutable state outward; mutations through intent methods.
- ❌ Network DTO used as database entity and UI model.
- ✅ Separate when schemas and ownership differ; avoid copying without reason.
Design exercise
Whiteboard a ride-booking feature. Include location updates, quote expiry, driver matching, cancellation, backgrounding, process death, and payment. Produce:
- ownership/boundary diagram
- state transition table
- repository/use-case contracts
- concurrency and retry decisions
- test strategy
- two ADRs with rejected alternatives
State the forces, ownership, invariants, dependency direction, failure/lifecycle behavior, tradeoffs, and verification. Pattern names come last.
Exercises
- Review a god ViewModel and propose an incremental migration.
- Contract-test a fake and production repository.
- Defend one deliberate violation of a preferred architecture rule.