Architecture: Bento vs Burrito

Architecture: Bento vs Burrito

Bbe9718bebdafbdc8dabbe3cadf1bc46?s=128

Keishin Yokomaku

June 17, 2016
Tweet

Transcript

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

    #1 
  2. @KeithYokoma • Keishin Yokomaku at Drivemode, Inc. • Work •

    Android apps • Android Training and its publication • Like • Bicycle, Photography, Tumblr and Motorsport • hoge 
  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. 
  4. About “Drivemode” • Available features • Contacts: Call and Message

    • Navigation control • Music playback control and playlist access • Application launcher 
  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 
  6. Available on Play Store! http://bit.ly/1LYdxAg 

  7.  Application Requirements Login and save user profile Choose favorite

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

    contacts Choose favorite navigation app Control music playback Internet Access Database Preferences IPC
  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…
  10. –Johnny Appleseed “͜͜ʹҾ༻Λೖྗ͍ͯͩ͘͠͞ɻ” 

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

  12. Application Components  Activity Fragment View BroadcastReceiver Service ContentProvider

  13. Activity responsibility  Activity MainActivity UI Event handler System service

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

    calls AsyncTaskLoader UI State management ʜ \
  15. None
  16. • Everything is mixed into one activity. • You cannot

    get rid of cilantro even if you hate it. Burrito architecture 
  17. None
  18. Better Architecture 

  19. Practices  MVC MVP MVVM …

  20. Practices  ModelViewController ModelViewPresenter ModelViewViewModel …

  21. “Which one will fit my project?” 

  22. Let’s simplify it 

  23. 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 
  24. –@rallat 

  25. Presentation Bento

  26. Presentation Model

  27. 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…). 
  28. –Someone “Model can be Burrito” 

  29. Model as a Bento 

  30. Model as a Bento  REST API Client

  31. Model as a Bento  Cache Database

  32. Model as a Bento  Preferences

  33. Model as a Bento  Model Interface

  34. Model as a Bento  Main Thread Worker Thread

  35. Model as a Bento 

  36. 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 
  37. Model as a Bento // REST Client interface public interface

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

    FooBarRestGateway { @GET(“foo/bar”) Observable<List<FooBarData>> requestFooBar(); } // Database Manager interface public interface FooBarDatabaseClient { Observable<List<FooBarData>> fetchFooBar(); } 
  39. Model as a Bento // Model Interface class public class

    FooBarRepository { private final FooBarRestGateway mGateway; private final FooBarDatabaseClient mDbClient; public Observable<List<FooBarData>> fooBarList() { return Observable.<List<FooBarData>>concat( mDbClient.fetchFooBar(), mGateway.requestFooBar() ).first(list -> list != null) .subscribeOn(Schedulers.io()); } }  https://speakerdeck.com/hkurokawa/5-rxjava-tips-you-might-not-know
  40. Model as a Bento // Model Interface class public class

    FooBarRepository { private final FooBarRestGateway mGateway; private final FooBarDatabaseClient mDbClient; public Observable<List<FooBarData>> fooBarList() { return Observable.<List<FooBarData>>concat( mDbClient.fetchFooBar(), mGateway.requestFooBar() ).first(list -> list != null) .subscribeOn(Schedulers.io()); } }  https://speakerdeck.com/hkurokawa/5-rxjava-tips-you-might-not-know
  41. Model as a Bento // Model Interface class public class

    FooBarRepository { private final FooBarRestGateway mGateway; private final FooBarDatabaseClient mDbClient; public Observable<List<FooBarData>> fooBarList() { return Observable.<List<FooBarData>>concat( mDbClient.fetchFooBar(), mGateway.requestFooBar() ).first(list -> list != null) .subscribeOn(Schedulers.io()); } }  https://speakerdeck.com/hkurokawa/5-rxjava-tips-you-might-not-know
  42. Bento and Clean Architecture  Clean Architecture: Data Layer using

    Repository Pattern Bento
  43. Don’t touch Bento directly  Activity Activity Activity I want

    a healthy one! I want no-smelling one! I want one with !
  44. ʢPhoto by SAKURAKO - Do not get mad !/ MJ/TR

    (´ŋТŋ)ʣ
  45. Domain layer  Activity Activity Activity Domain Domain Domain

  46. Domain layer  Activity Activity Activity

  47. Domain layer  Activity Activity Activity Filter out smelling foods

  48. Domain layer  Activity Activity Activity Filter out unhealthy foods

  49. Domain layer  Activity Activity Activity +

  50. Domain layer  Clean Architecture: 3 layer architecture

  51. Domain layer  Activity Activity Activity Clean Architecture: 3 layer

    architecture
  52. 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 
  53. Architecture: Bento vs Burrito Thank you for listening! Keishin Yokomaku

    @ Drivemode, Inc. umeda.apk #1