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

Common Mobile Architecture

Common Mobile Architecture

As mobile development finds its way into the enterprise world, the applications become increasingly more complex.

Quick and dirty solutions lead to unmaintainable, and even erroneous code. By applying an architecture using design patterns and proven best practices we avoid these problems.

And thus the need for a good architecture becomes ever so important. In search of a good methodology we discovered that, not surprisingly, the needs in various environments are the same, and can be tackled in the same way. Whether it's Android, HTML 5/CSS 3/JavaScript, iOS and maybe even other mobile platforms, the main building blocks of this architecture might always come back. The gains of a common architecture is that the principals behind it only need to be explained once, and can be applied on different platforms.

We will give examples "from the trenches", showing the various problems, and work towards their solutions on different platforms.

Filip Maelbrancke

April 17, 2013
Tweet

More Decks by Filip Maelbrancke

Other Decks in Programming

Transcript

  1. ! Nerdvana “There are two ways of constructing a software

    design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies.” Tony Hoare
  2. Naive client GUI thread View Remoting logic Transformation logic Storage

    logic Presentation logic CRUD operations Save data structure Remote Local storage
  3. A less naive approach GUI thread View Presentation logic Background

    thread Remote Local storage CRUD operations Save data structure Service Remoting logic Transformation logic Storage logic
  4. Working towards a layered architecture Communication with remote systems Caching

    data in local storage Translation of data Keeping state of the cached data Passing data to the view layer
  5. Data Synchronisation What is still missing? Something to tie the

    services together and communicate with the GUI layer. Something to keep track of the state of our local data. Eg. when do we need to refresh the data from the backend?
  6. Statekeeper Remoting Service Remote API HTTP/JSON/XML AMF ProtocolBuffers Adaptor Data

    Source Entities Local Service Data Provider State Keeper GUI Layer
  7. Non-blocking? We now know that we will handle data using

    the data provider, which encapsulates all data handling logic. However, we still didn’t tackle the “my-main- thread-is-blocked-for-a-while” problem.
  8. Making things asynchronous: Events Pros: Loose coupling Easy to implement

    Cons: Hard to maintain Hard to follow where all events end up Event storms!
  9. Making things asynchronous: Callbacks Pros: Loose coupling Easy to refactor

    Easy to follow and to maintain Cons: Little more complex then eventing
  10. Responder explained caller callee calls • on X • on

    Y • on Z immediately returns • on X • on Y • on Z • on X • on Y • on Z other actors • on X • on Y • on Z
  11. Tying it up! Remoting Service Remote API HTTP/JSON/XML AMF ProtocolBuffers

    Adaptor Data Source Entities Local Service Data Provider State Keeper GUI Layer Responder/ Callhandle Responder/ Callhandle
  12. DRY

  13. CRUD via REST Method Operation Change? Idempotent? GET GET /

    SELECT ✔ ✔ POST INSERT ✘ ✘ PUT UPDATE ✘ ✔ DELETE DELETE ✘ ✔
  14. POST Data Provider + State Keeper Remote Service Data Source

    insert set STATE_INSERTING update clear STATE_INSERTING
  15. Data Provider 1 Responder Callhandle 1 No local data Front

    layer Local Service 2 State Watcher 3 Remote Service 4 Responder Callhandle 4 5 State Keeper 6 7
  16. Data up-to-date Front layer Data Provider 1 Responder Callhandle 1

    Local Service 2 State Watcher 3 State Keeper 4
  17. Data outdated Front layer Data Provider 1 Responder Callhandle 1

    Local Service 2 State Watcher 3 4 8 Up-to- date data Remote Service 5 Responder Callhandle 5 6 State Keeper 7 Stale data
  18. Conclusions Do not call backend logic inside UI threads Start

    long running operations from a background service Persist early and persist often Minimize the network usage
  19. Suggested reading Design patterns: elements of reusable object-oriented software Gamma

    et al. (978-0201633610) Patterns of enterprise application architecture Fowler et al. (978-0321127426) The pragmatic programmer Hunt, Thomas (978-0201616224)