Upload
nicola-zaghini
View
455
Download
0
Embed Size (px)
Citation preview
UNCLE BOB HTTPS://8THLIGHT.COM
MUTUAL MOBILE ENGINEERING
FANCY A SLICE 🍰😬 ?
We strive to make travel better and to enable our customers to shape new and
superior travel experiences with innovative, personalised mobile and
digital offerings.
The road to (B)VIPER
DEFINING THE MODULE
FlightSearch
FlightAvailability
FlightSummary
WHAT IS AN APPLICATION ?
FlightSearch
FlightAvailability
FlightSummary
WHAT IS A MODULE ?
HOW DO WE WANT MODULES?Composable
Application = SUM ( Modules )Module = SUM ( Components )
Black boxExpose clear APIs.
The outside world should not know internal details.
Testable“Isolation checks” made simple!
Independent of User Interface User interface must change without impacting the rest of the system.
Independent of FrameworksDatabase, UI framework, Network, …
SimpleSmall and well defined parts delivering one function.
MODULES
APPLICATION = SUM (MODULES )
Availability ServiceBooking ServicePayment ServiceCheck-in Service
…
Mobile Application
Remote Services
DESIGN THE MODULE
C4 MODELS A WAY OF COMMUNICATING SOFTWARE SYSTEMS
Mobile Application
Flight Search
DESIGN THE MODULE
Availability ServiceBooking ServicePayment ServiceCheck-in Service
…
Flight Availability
Flight Summary
Services &
Entities
Services &
Entities
FlightAvailability
Flight Search
Flight Summary
FlightAvailability
UIView Controller
Flight Search
Flight Summary
Services &
Entities
1K+ lines UIViewController 😱?
I think we can do better
😎
View ModelView
User Interface No B. Logic
Data Model Converter for the View Apply Application BL
Routing
Flight Search
Flight Summary
MVVM APPROACH
Services &
Entities
Domain Model to View Model mapping
User interaction
Apply Business Rules
Routing
Overall, there are too many reason to change the ViewModel - Single responsibility principle violated
VIEW MODEL RESPONSIBILITIES
View Model
FlightAvailability
View
User Interface No B. Logic
Flight Search
Flight Summary
Data Model Converter for the View Listen to View events Apply Application BL
Routing
Services &
Entities
View Model
FlightAvailability
View
User Interface No B. Logic
Next Module Navigation
RouterFlight Search
Flight Summary
Data Model Converter for the View Listen to View events Apply Application BL
Services &
Entities
protocol WeatherListRouter { func navigateToDetail(location: Location) func navigateToAddWeatherLocation() }
ROUTER CONTRACT
View Model
FlightAvailability
View
User Interface No B. Logic
Next Module Navigation
RouterFlight Search
Flight Summary
Data Model Converter for the View Listen to View events Apply Application BL
Services &
Entities
Presenter
FlightAvailability
View
User Interface No B. Logic
Next Module Navigation
Router
View Model
Listen to View events
Apply App BL
Data Model Converter
for the View
Flight Search
Flight Summary
Services &
Entities
protocol WeatherListPresenter { func loadContent() func presentWeatherDetail(location: String) func presentAddWeatherLocation() }
PRESENTER CONTRACT
protocol WeatherListView { func displayLocationList(vm: LocationListVM) func displayError(errorMessage: String) }
VIEW CONTRACT
struct LocationListViewModel { let locations: [LocationViewModel] }
struct LocationViewModel { let locationId: String let name: String let detail: String }
VIEW MODEL
Presenter
FlightAvailability
View
User Interface No B. Logic
Next Module Navigation
Router
View Model
Data Model Converter
for the View
Flight Search
Flight Summary
Listen to View events
Apply App BR
Services &
Entities
Presenter
FlightAvailability
View
User Interface No B. Logic
Next Module Navigation
Router
View Model
Listens to View events
Data Model Converter
for the View
Interactor
Apply Application Business Rules
Flight Search
Flight Summary
Services &
Entities
public protocol WeatherListInteractor { func locations() -> [Location] }
INTERACTOR CONTRACT
PresenterView
Next Module Navigation
Router
View Model
Interactor
- loadContent- presentWeatherDetail
Flight Search
- locations
LocationListViewModel
- displayLocations
- navigateToWeatherDetail
COMPONENTS INTERACTION
Cool, are we there yet?
…nope 🚀
Presenter
FlightAvailability
View
User Interface No B. Logic
Next Module Navigation
Router
View Model
Listens to View events
Data Model Converter
for the View
Interactor
Flight Search
Flight Summary?🤔?
Apply Application Business Rules
Services &
Entities
Presenter😐
User Interface No B. Logic
Next Module Navigation
😐
😐
Listens to View events
Data Model Converter
for the View
😐
Flight Search
Flight Summary?🤔?
Apply Application Business Rules
TESTING IS SIMPLE
Services &
Entities
Presenter
FlightAvailability
View
User Interface No B. Logic
Next Module Navigation
Router
View Model
Listens to View events
Data Model Converter
for the View
Interactor
Flight Search
Flight Summary?🤔?
Apply Application Business Rules
Services &
Entities
Presenter
FlightAvailability
View
User Interface No B. Logic
Next Module Navigation
Router
View Model
Listens to View events
Data Model Converter
for the View
Interactor
Flight Search
Flight Summary
Builder
😀
Creates and wires
components
Apply Application Business Rules
Services &
Entities
Knows how to wire the Module components.Knows concrete Components implementation.
Dependency Injection.
Module exposed as Black Box ViewController to the outside world.
InputParameters
ViewController
THE BUILDER COMPONENT
Builder
public protocol WeatherListBuilder { func buildModule() -> UIViewController? }
BUILDER CONTRACT
Presenter
FlightAvailability
View
User Interface No B. Logic
Next Module Navigation
Router
View Model
Listens to View events
Data Model Converter
for the View
Interactor
Flight Search
Flight SummaryBuilder
Creates and wires
components
Apply Application Business Rules
Services &
Entities
Presenter
FlightAvailability
My View
User Interface No B. Logic
Next Module Navigation
My Router
View Model
Listens to View events
Data Model Converter
for the View
Interactor
Flight Search
Flight SummaryBuilder
Creates and wires
components
Apply Application Business Rules
Services &
Entities
Presenter
FlightAvailability
View
User Interface No B. Logic
Next Module Navigation
Router
View Model
Listens to View events
Data Model Converter
for the View
Interactor
Apply Application Business Rules
Services &
Entities
FANCY A SLICE 🍰😬 ?
Entities and Services
Interactor
Presenter
View Model
View
Router
MODULE
(B)uilder
Current status.
Composable ✅ Application = SUM ( Modules )Module = SUM ( Components )
Black box ✅The outside world should not know internal details.
Exposes clear APIs.
Testable ✅Promoting easy isolation checks of the parts and the whole.
Independent of User Interface ✅User interface must change easily without impacting the rest of the system.
Independent of Frameworks ✅Database, UI framework, Network, …
Simple ✅Small and well defined parts delivering one function.
Sending information between (B)VIPER Modules
… what if To Module is modal?To_Module accepts a delegate which is a component of the From_Module (usually the Presenter)
Router
From Module To Module
Router provides out data needed
by the next Builder
Builder
TIP #1
Window
Router
InteractorView (VC) Presenter
References among components
Strong
Weak
Strong
Weak
Weak
Strong
Strong
When the ViewController is deallocated, the whole module gets deallocated.
TIP #2
Crossing boundaries Models
TIP #3
Dependency Management Toolsupporting Semantic Versioning!
(CocoaPod, Carthage)
Dependency Injection Container
(Typhoon, Swinject)
TIP #4
INTEGRATED TEST ARE A SCAM by J.B. Rainsberger
SIMPLE MADE EASY by Rich Hickey
WATCH LIST SUGGESTIONS 👀
CLEAN ARCHITECTURE AND DESIGN by Robert C. Martin
No such thing asone-size fits all.
@nzaghini [email protected]
(B)VIPER example repo: http://bit.ly/B_VIPER
I use unsplash.com to make slides look great!