Share
Embed
iOSCon.pdf
Nicola Zaghini
June 01, 2016
Transcript
39 slides
-
MASTERING REUSE A JOURNEY INTO APPLICATION MODULARISATION WITH VIPER Nicola
Zaghini - [email protected] - @nzaghini iOSCon 2016 -
Grow the Business • Deliver quality and reliable solutions •
Reduce time to market • Reduce the costs MASTERING REUSE - THE GOAL -
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. -
SOFTWARE REUSE - DEFINITION Process of implementing software systems
using existing software components or modules. -
Horizontal domain agnostic LOW competitive advantage Vertical domain specific HIGH
competitive advantage SOFTWARE REUSE - APPROACHES -
SOFTWARE REUSE - GUIDELINE Reusability as a consequence of modularity.
Identify the right module to master reuse. -
Availability Service Booking Service Payment Service Check-in Service … IDENTIFY
THE MODULE Mobile Application Remote Services -
Mobile Application IDENTIFY THE MODULE Availability Service Booking Service Payment
Service Check-in Service … Application Layer Remote Services Service Layer -
Remote Services Mobile Application Service Layer Availability Service Booking Service
Payment Service Check-in Service … IDENTIFY THE MODULE - MICRO-SERVICE STYLE Avail. Service Booking Service Payment Service Application Layer -
MICRO-SERVICE STYLE - ADVANTAGES Modularity simple parts represented by well
defined contracts Composition final program as sum result of many simple parts Simplicity small and well defined parts delivering one function Testability promotes isolation checks and test doubles -
MICRO-SERVICE STYLE - INFRASTRUCTURE Versioning (semantic) Discovering and composition Lifecycle
(scoping) Dependency Management Tool (CocoaPod, Carthage) Dependency Injection Container (Typhoon, SwiftInject, Dip) -
Remote Services Mobile Application Service Layer Availability Service Booking Service
Payment Service Check-in Service … IDENTIFY THE MODULE - MICRO-SERVICE STYLE Avail. Service Booking Service Payment Service Application Layer -
Application Layer Mobile Application A Mobile Application B
Mobile Application C IDENTIFY THE MODULE Remote Services Avail. Service Booking Service Payment Service Application Layer Application Layer Service Layer -
Application Layer Mobile Application A Mobile Application B
Mobile Application C IDENTIFY THE MODULE Remote Services Avail. Service Booking Service Payment Service Application Layer Application Layer REUSE ? -
Screen based reuse. Each screen is a Module. • A
Module identifies business value by fulfilling a set of user stories. • Modules have configuration and customisation capabilities (UI, Flow, BL,…) as every customer wants to be unique. • Modules are black boxes for the outside world. DEFINE REUSE -
DESIGN THE MODULE Flight Search Flight Availability Flight Summary I
want different user interface! I want different flow! My Logic here is slightly different… -
Router THE ROUTER COMPONENT Next Module Navigation Flight Search Flight
Summary Flight Selection Services -
View THE VIEW COMPONENT Flight Search Flight Summary Flight Selection
Next Module Navigation User Interface No B. Logic Services Router -
View Model THE VIEW MODEL COMPONENT Flight Search Flight Summary
Flight Selection Next Module Navigation Data Model Converter for the View Listens to View events Business Rules User Interface No B. Logic View Services Router -
THE VIEW MODEL COMPONENT Responsibilities of a single component: •
Domain Model to View Model mapping • User interaction • Apply business rules • Service orchestration Overall, there are too many reason to change the ViewModel - Single responsibility principle violated. -
THE VIEW MODEL COMPONENT Data Model Converter for the View
Listens to View events Business Rules Flight Search Flight Summary Flight Selection Next Module Navigation User Interface No B. Logic View Model View Services Router -
View Model THE PRESENTER COMPONENT Flight Search Flight Summary Flight
Selection Next Module Navigation Listens to View events Business Rules Data Model Converter for the View User Interface No B. Logic Presenter View Services Router -
Interactor THE INTERACTOR COMPONENT Listens to View events Data Model
Converter for the View Flight Search Flight Summary Flight Selection Next Module Navigation User Interface No B. Logic Business Rules View Model Presenter View Services Router -
Builder THE BUILDER COMPONENT Listens to View events Data Model
Converter for the View Flight Search Flight Summary Flight Selection Next Module Navigation User Interface No B. Logic Business Rules Interactor View Model Presenter View Services Router -
Knows concrete implementation. Knows how to compose the Module. Module
exposed as Black Box ViewController to the outside world. THE BUILDER COMPONENT Builder Input Parameters View Controller -
Builder THE BUILDER COMPONENT Listens to View events Data Model
Converter for the View Flight Search Flight Summary Flight Selection Next Module Navigation User Interface No B. Logic Business Rules Interactor View Model Presenter View Services Router -
TESTING Easy isolation checks for all components by mocking the
others! Interactor View Model Presenter View Router -
Sending information between (B)VIPER Modules … and when To Module
is modal? To_Module accepts a delegate which is a component of the From_Module (usually the Presenter) Router FEW GOTCHAS From Module To Module Router provides out data needed by the next Builder Builder -
Window Router Interactor View (VC) Presenter FEW GOTCHAS References among
components Strong Weak Strong Weak W eak Strong Strong When the ViewController is deallocated, the whole module gets deallocated. -
FEW GOTCHAS • Sometimes is hard to be DRY, but
you can use Shared Modules (don’t forget about coupling!) • Specialisation of components via Subclassing or Decoration • Handle Modules distribution and versioning via CocoaPods and use Subspecs for component granularity • Changes to the Module may sometimes touch many internal components