Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Nicola Zaghini: BREAK THE MONOLITH WITH (B)VIPE...

Realm
October 22, 2016

Nicola Zaghini: BREAK THE MONOLITH WITH (B)VIPER MODULES. OR HOW DO I START MODULARISING MY CODE FOR A BETTER (ENGINEERING) LIFE.

In the software engineering business there is no one fits all solution but when design patterns arise in the community it is important to understand the reasons why they were originated and how to tweak them for our purposes. This talk will explore the VIPER design with top-down approach, deriving the design decisions from quality attributes of a software system including modularity, reusability, testability, single responsibility and more. You will learn the reasons why the design was initially conceived (Clean Architecture by Uncle Bob) then formalised for mobile (by Mutual Mobile) and how to revise it to fit your purposes. Eventually a modified version of the design, friendly called (B)VIPER, will be discussed as improvement for better reuse of modules among different teams.

Realm

October 22, 2016
Tweet

More Decks by Realm

Other Decks in Technology

Transcript

  1. 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.
  2. HOW DO WE WANT MODULES? Composable
 Application = SUM (

    Modules )
 Module = SUM ( Components ) Black box
 Expose 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 Frameworks
 Database, UI framework, Network, … Simple
 Small and well defined parts delivering one function.
  3. Availability Service
 Booking Service
 Payment Service
 Check-in Service
 … Mobile

    Application Remote Services DESIGN THE MODULE C4 MODELS A WAY OF COMMUNICATING SOFTWARE SYSTEMS
  4. Mobile Application Flight Search DESIGN THE MODULE Availability Service
 Booking

    Service
 Payment Service
 Check-in Service
 … Flight Availability Flight Summary Services & Entities
  5. View Model View User Interface
 No B. Logic Data Model

    Converter for the View Apply Application BL Routing Flight Search Flight Summary MVVM APPROACH Services & Entities
  6. 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
  7. View Model Flight
 Availability 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
  8. View Model Flight
 Availability View User Interface
 No B. Logic

    Next Module Navigation Router Flight Search Flight Summary Data Model Converter for the View Listen to View events Apply Application BL Services & Entities
  9. View Model Flight
 Availability View User Interface
 No B. Logic

    Next Module Navigation Router Flight Search Flight Summary Data Model Converter for the View Listen to View events Apply Application BL Services & Entities
  10. Presenter Flight
 Availability 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
  11. struct LocationListViewModel { let locations: [LocationViewModel] } struct LocationViewModel {

    let locationId: String let name: String let detail: String } VIEW MODEL
  12. Presenter Flight
 Availability 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
  13. Presenter Flight
 Availability 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
  14. Presenter View Next Module Navigation Router View Model Interactor -

    loadContent
 - presentWeatherDetail Flight Search - locations LocationListViewModel - displayLocations - navigateToWeatherDetail COMPONENTS INTERACTION
  15. Presenter Flight
 Availability 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
  16. 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
  17. Presenter Flight
 Availability 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
  18. Presenter Flight
 Availability 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
  19. Knows how to wire the Module components.
 Knows concrete Components

    implementation.
 Dependency Injection.
 Module exposed as Black Box 
 ViewController to the outside world. Input
 Parameters View
 Controller THE BUILDER COMPONENT Builder
  20. Presenter Flight
 Availability 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
  21. Presenter Flight
 Availability 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 Summary Builder Creates and wires components Apply Application
 Business Rules Services & Entities
  22. Presenter Flight
 Availability 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
  23. 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.
  24. 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
  25. Window Router Interactor View (VC) Presenter References among components Strong

    Weak Strong Weak W eak Strong Strong When the ViewController is deallocated, the whole module gets deallocated. TIP #2
  26. 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