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

Journey to understand Observer and Pub-Sub Pattern

Journey to understand Observer and Pub-Sub Pattern

Amanjeet Singh

October 20, 2018
Tweet

More Decks by Amanjeet Singh

Other Decks in Programming

Transcript

  1. • Derive: What is observer pattern and pub sub pattern

    and why do we need them. • Given: iPhone, User, Different situations • Assumption: Let’s assume that there are no observers or pub sub patterns. What will happen: 1. No real time modifying view controllers:
  2. 2. Periodic Monitoring increases • Regular monitoring in regular intervals

    • Periodic networking calls • Periodic monitoring of different resources.
  3. • Result: Nobody wants this and thus we can say

    we need someone to tell about the change.
  4. Observer Pattern “The observer pattern is a software design pattern

    in which an object, called the subject maintains a list of its dependents, called observers, and notifies automatically of any state changes, usually by calling one of their methods.” -Wikipedia
  5. Pub Sub Pattern • Pub: Publishers • Sub: Subscribers •

    A software design pattern where there are senders of some messages and they send the messages to the receivers called the subscribers. -Unknown
  6. APIs providing such facilities • Notification Center • Observation Protocols

    • RxSwift • Grand Central Dispatch • MQTT • Delegates
  7. Publish Subjects • Subjects: Observable + Observer • It emits

    all the subsequent items of the source Observable at the time of subscription.
  8. Use case • Event Bus to broadcast the subscribers about

    the events of your journey. • Beginning of journey • Ending of Journey • Journey updates • Any journey related channel
  9. Steps to success!! • Create some dummy locations • Create

    a singleton class to set the Journey Events and get the journey events
  10. Steps to success!! • Create some dummy locations • Create

    a singleton class to set the Journey Events and get the journey events
  11. Steps to success!! • Create some dummy locations • Create

    a singleton class to set the Journey Events and get the journey events
  12. Steps to success!! • Create some dummy locations • Create

    a singleton class to set the Journey Events and get the journey events
  13. • Subscribe to the “Resource” in viewDidLoad( ) • Now

    you can get the events wherever you write this subscribe code
  14. • Subscribe to the “Resource” in viewDidLoad( ) • Now

    you can get the events wherever you write this subscribe code
  15. • Subscribe to the “Resource” in viewDidLoad( ) • Now

    you can get the events wherever you write this subscribe code