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

RIBs Architecture - why Uber invented their own wheel

RIBs Architecture - why Uber invented their own wheel

Originally posted here: https://speakerdeck.com/dimaosa/ribs-architecture-why-uber-invented-their-own-wheel

RIBs Architecture was presented by UBER in 2017, since than it become an architecture which gain attention all around the globe.

How UBER solved this problems?
Why did they develop their own solution?
Who should consider this architecture?
How to use it?
Where to start?

This talk was made for CocoaHeads Kyiv #14 which took place Oct 6 2018.

CocoaHeads Ukraine

October 06, 2018
Tweet

More Decks by CocoaHeads Ukraine

Other Decks in Programming

Transcript

  1. RIBs Architecture.
    Why UBER invented their own wheel?

    View Slide

  2. Let’s recall the situation when you open
    someones/yours ViewController and you have
    no clue, What the f*ck is going on here?
    • We know what is going on here

    • We don’t ask other person to explain us what is going on here

    • We write code that is possible to support and extend

    • Easy to add New features

    • Easy to reuse Views

    View Slide

  3. Inputs Outputs
    Imagine that every part is a
    component

    View Slide

  4. Beer opener
    Bottle of beer
    Electricity
    Bottle
    is opened !
    Unable to
    open a beer
    Beer was
    opened
    Inputs Outputs

    View Slide

  5. Things to consider before
    creating new "Part"
    What are your inputs. (Without inputs your part will not work)

    What are your outputs. (What are you trying to achieve by
    implementing it)

    If we attach Part

    (child) to Part

    (parent),

    must satisfy all

    inputs and outputs

    View Slide

  6. More examples:

    View Slide

  7. Our body is a perfect example of a
    set of reasonably connected parts
    System Parts

    View Slide

  8. Our body is a perfect example of a
    set of reasonably connected parts

    View Slide

  9. RIBs
    Router Ineractor
    Builder

    View Slide

  10. Massive View Controller

    View Slide

  11. Massive View Controller

    View Slide

  12. State
    Management

    View Slide

  13. State Management

    View Slide

  14. State Management

    View Slide

  15. Search Station RIB

    View Slide

  16. Ticket Search RIB ⚙

    View Slide

  17. RIB parts
    Interactor
    Router ViewController
    Builder
    Component
    Manage RIBs
    Dependency

    View Slide

  18. Communication

    View Slide

  19. Communication : Upwards

    View Slide

  20. Communication
    Upwards Question from
    GitHub.com
    Question: The issue I'm having is finding a good way of passing data from children
    components (D, E, F) to component in another "subtree" (G).
    Currently, I'm passing this data through every parent component (for example D -> C -
    > B -> A -> Root) using Listeners and then I'm using Rx stream to pass data from Root
    to G.
    This creates a lots of boilerplate and I wonder if there's a better way of doing it.
    https://github.com/uber/RIBs/issues/232
    Answer: You could pass Mutable Rx stream from Root to children (D, E, F), and make changes in D, E, F,
    after that pass NonMutable Rx Stream to G (if you need only listen). So in that way you don't need to use
    Listeners in A, B, C

    View Slide

  21. Action
    Action
    Action
    Present here

    View Slide

  22. Communication : Downwards

    View Slide

  23. Streams
    - LocationManagerStream
    - ProfileManager
    - TrainColorPalette
    - TrainService
    - SearchLocationsStream
    ⚙ - PreferencesStream
    - TicketsStream
    Typically, we store state inside streams of immutable
    models that re-emit values when the details change.

    View Slide

  24. Streams

    View Slide

  25. Streams
    • MutableStream and Stream

    View Slide

  26. Streams

    View Slide

  27. Streams

    View Slide

  28. Streams

    View Slide

  29. No architecture
    View Controller vision
    Day 1 Day 30

    View Slide

  30. RIBs vision
    Day 1 Day 30

    View Slide

  31. Why UBER invented their
    own wheel?
    • Isolation and Testability. Classes must be easy to unit test and reason about in isolation.
    Individual RIB classes have distinct responsibilities like: routing, business, view logic, creation. Plus, most RIB logic
    is decoupled from child RIB logic. This makes RIB classes easy to test and reason about independently.

    • Tooling for developer productivity. RIBs come with IDE tooling around code
    generation, memory leak detection, static analysis and runtime integrations - all which improve developer
    productivity for large teams or small.

    • An architecture that scales. This architecture has proven to scale to hundreds of
    engineers working on the same codebase and apps with hundreds of RIBs.

    • Shared architecture across iOS and Android. Build cross-platform apps
    that have similar architecture, enabling iOS and Android teams to cross-review business logic code.

    • Open-Closed Principle. Whenever possible, developers should be able to add new features
    without modifying existing code. This can be seen in a few places when using RIBs. For example, you can attach or
    build a complex child RIB that requires dependencies from its parent with almost no changes to the parent RIB.

    View Slide

  32. How to add 50 screens feature, spent 8 months, and
    remain linear speed for adding new features… in feature

    View Slide

  33. For whom?
    •More than 2 people

    •Feature, feature and one more feature

    •Don’t want to write bad code

    •Never stop scaling

    •Invest your time to learn new
    •Proactive

    View Slide

  34. How to start?
    Installation for iOS
    CocoaPods
    To integrate RIBs into your project add the following to your
    Podfile:

    pod 'RIBs', '~> 0.9'
    Carthage
    To integrate RIBs into your project using Carthage add the
    following to your Cartfile:

    github "uber/RIBs" ~> 0.9

    View Slide

  35. Where to go next?
    RIBs engineer talk about architecture
    https://www.youtube.com/watch?v=FfwZSk6VRVY
    RIBs Github
    https://github.com/uber/RIBs
    RIBs Slack channel, talk with creators one-to-one
    uber-ribs.slack.com
    Engineering Scalable, Isolated Mobile Features with
    Plugins at Uber
    https://eng.uber.com/plugins/

    View Slide

  36. Wanna talk more?
    facebook
    https://www.facebook.com/dima.osadchy
    email
    [email protected]

    View Slide

  37. The End
    ?
    Or just the beginning

    View Slide