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

Architecture: Bento vs Burrito

Architecture: Bento vs Burrito

Keishin Yokomaku

June 17, 2016
Tweet

More Decks by Keishin Yokomaku

Other Decks in Technology

Transcript

  1. Architecture: Bento vs Burrito
    Keishin Yokomaku @ Drivemode, Inc.
    umeda.apk #1

    View full-size slide

  2. @KeithYokoma
    • Keishin Yokomaku at Drivemode, Inc.
    • Work
    • Android apps
    • Android Training and its publication
    • Like
    • Bicycle, Photography, Tumblr and Motorsport
    • hoge

    View full-size slide

  3. About “Drivemode”
    • “No Look” driving interface running on the phone.
    • Simplify the way drivers user their phone

    while driving.
    • Allows them to focus on the road.

    View full-size slide

  4. About “Drivemode”
    • Available features
    • Contacts: Call and Message
    • Navigation control
    • Music playback control and playlist access
    • Application launcher

    View full-size slide

  5. About “Drivemode”
    • Overlays on any applications
    • You can see navigation while playback controlling
    • Help users understanding what they are doing
    • Sound & voice feedback
    • Big UI and touch feedback effect

    View full-size slide

  6. Available on Play Store!
    http://bit.ly/1LYdxAg

    View full-size slide


  7. Application Requirements
    Login and save user profile
    Choose favorite contacts
    Choose favorite navigation app
    Control music playback
    ʜ

    View full-size slide


  8. Application Requirements
    Login and save user profile
    Choose favorite contacts
    Choose favorite navigation app
    Control music playback
    Internet Access
    Database
    Preferences
    IPC

    View full-size slide


  9. Application Requirements
    Internet Access
    Database
    Preferences
    IPC
    Protocol, network state, cache strategy, etc…
    Content Uri, projection, selection, order, etc…
    Data type, preference name, etc…
    AIDL, media session and controller, etc…

    View full-size slide

  10. –Johnny Appleseed
    “͜͜ʹҾ༻Λೖྗ͍ͯͩ͘͠͞ɻ”

    View full-size slide

  11. “Who is responsible for each features/requirements?”

    View full-size slide

  12. Application Components

    Activity
    Fragment
    View
    BroadcastReceiver
    Service
    ContentProvider

    View full-size slide

  13. Activity responsibility

    Activity
    MainActivity
    UI Event handler
    System service calls
    AsyncTaskLoader
    UI State management
    ʜ
    \

    View full-size slide

  14. Activity responsibility

    Activity
    MainActivity
    UI Event handler
    System service calls
    AsyncTaskLoader
    UI State management
    ʜ
    \

    View full-size slide

  15. • Everything is mixed into one activity.
    • You cannot get rid of cilantro even if you hate it.
    Burrito architecture

    View full-size slide

  16. Better Architecture

    View full-size slide

  17. Practices

    MVC
    MVP
    MVVM

    View full-size slide

  18. Practices

    ModelViewController
    ModelViewPresenter
    ModelViewViewModel

    View full-size slide

  19. “Which one will fit my project?”

    View full-size slide

  20. Let’s simplify it

    View full-size slide

  21. Keywords
    • Single Responsibility Principle
    • “A class should have only one reason to change.”
    • Clean Architecture
    • “Independent of Frameworks”, “Testable”, “Independent of UI”,
    “Independent of Database”, “Independend of any external agency”.
    • For this time, let’s talk about “Model” layer

    View full-size slide


  22. Presentation Bento

    View full-size slide


  23. Presentation Model

    View full-size slide

  24. The so-called “Model”
    • Model has “Business Logic” and “Data”.
    • One model contains various kind of “Business Logic” and “Data”.
    • How to retrieve and store data(REST API, Database Cache, etc…)
    • How to convert serialized data to value object(entity)
    • How to order collection data
    • etc…
    • Model may have blocking procedure(Network I/O, File I/O, etc…).

    View full-size slide

  25. –Someone
    “Model can be Burrito”

    View full-size slide

  26. Model as a Bento


    View full-size slide

  27. Model as a Bento


    REST API Client

    View full-size slide

  28. Model as a Bento


    Cache Database

    View full-size slide

  29. Model as a Bento


    Preferences

    View full-size slide

  30. Model as a Bento


    Model Interface

    View full-size slide

  31. Model as a Bento


    Main Thread
    Worker Thread

    View full-size slide

  32. Model as a Bento



    View full-size slide

  33. Model as a Bento
    • Build classes for each purpose(SRP)
    • REST Client class
    • Cache Database manager class
    • Preferences class
    • Combine all asynchronous tasks in Model Interface class using Rx/Promise

    View full-size slide

  34. Model as a Bento
    // REST Client interface
    public interface FooBarRestGateway {
    @GET(“foo/bar”)
    Observable> requestFooBar();
    }
    // Database Manager interface
    public interface FooBarDatabaseClient {
    Observable> fetchFooBar();
    }

    View full-size slide

  35. Model as a Bento
    // REST Client interface
    public interface FooBarRestGateway {
    @GET(“foo/bar”)
    Observable> requestFooBar();
    }
    // Database Manager interface
    public interface FooBarDatabaseClient {
    Observable> fetchFooBar();
    }

    View full-size slide

  36. Model as a Bento
    // Model Interface class
    public class FooBarRepository {
    private final FooBarRestGateway mGateway;
    private final FooBarDatabaseClient mDbClient;
    public Observable> fooBarList() {
    return Observable.>concat(
    mDbClient.fetchFooBar(),
    mGateway.requestFooBar()
    ).first(list -> list != null)
    .subscribeOn(Schedulers.io());
    }
    }

    https://speakerdeck.com/hkurokawa/5-rxjava-tips-you-might-not-know

    View full-size slide

  37. Model as a Bento
    // Model Interface class
    public class FooBarRepository {
    private final FooBarRestGateway mGateway;
    private final FooBarDatabaseClient mDbClient;
    public Observable> fooBarList() {
    return Observable.>concat(
    mDbClient.fetchFooBar(),
    mGateway.requestFooBar()
    ).first(list -> list != null)
    .subscribeOn(Schedulers.io());
    }
    }

    https://speakerdeck.com/hkurokawa/5-rxjava-tips-you-might-not-know

    View full-size slide

  38. Model as a Bento
    // Model Interface class
    public class FooBarRepository {
    private final FooBarRestGateway mGateway;
    private final FooBarDatabaseClient mDbClient;
    public Observable> fooBarList() {
    return Observable.>concat(
    mDbClient.fetchFooBar(),
    mGateway.requestFooBar()
    ).first(list -> list != null)
    .subscribeOn(Schedulers.io());
    }
    }

    https://speakerdeck.com/hkurokawa/5-rxjava-tips-you-might-not-know

    View full-size slide

  39. Bento and Clean Architecture


    Clean Architecture: Data Layer using Repository Pattern
    Bento

    View full-size slide

  40. Don’t touch Bento directly


    Activity
    Activity
    Activity
    I want a healthy one!
    I want no-smelling one!
    I want one with !

    View full-size slide

  41. ʢPhoto by SAKURAKO - Do not get mad !/ MJ/TR (´ŋТŋ)ʣ

    View full-size slide

  42. Domain layer


    Activity
    Activity
    Activity
    Domain
    Domain
    Domain

    View full-size slide

  43. Domain layer


    Activity
    Activity
    Activity



    View full-size slide

  44. Domain layer


    Activity
    Activity
    Activity



    Filter out smelling foods

    View full-size slide

  45. Domain layer


    Activity
    Activity
    Activity



    Filter out unhealthy foods

    View full-size slide

  46. Domain layer


    Activity
    Activity
    Activity



    +

    View full-size slide

  47. Domain layer

    Clean Architecture: 3 layer architecture

    View full-size slide

  48. Domain layer


    Activity
    Activity
    Activity



    Clean Architecture: 3 layer architecture

    View full-size slide

  49. Wrap up
    • Clean Architecture and Bento
    • Class separation according to Single Responsibility Principle
    • Combine several tasks using Rx/Promise
    • Data layer bento is Singleton
    • Modify data in Domain layer
    • Don’t Burrito, do Bento

    View full-size slide

  50. Architecture: Bento vs Burrito
    Thank you for listening!
    Keishin Yokomaku @ Drivemode, Inc.
    umeda.apk #1

    View full-size slide