Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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.

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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…

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

“Who is responsible for each features/requirements?”

Slide 12

Slide 12 text

Application Components Activity Fragment View BroadcastReceiver Service ContentProvider

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

Better Architecture

Slide 19

Slide 19 text

Practices MVC MVP MVVM …

Slide 20

Slide 20 text

Practices ModelViewController ModelViewPresenter ModelViewViewModel …

Slide 21

Slide 21 text

“Which one will fit my project?”

Slide 22

Slide 22 text

Let’s simplify it

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

–@rallat

Slide 25

Slide 25 text

Presentation Bento

Slide 26

Slide 26 text

Presentation Model

Slide 27

Slide 27 text

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…).

Slide 28

Slide 28 text

–Someone “Model can be Burrito”

Slide 29

Slide 29 text

Model as a Bento

Slide 30

Slide 30 text

Model as a Bento REST API Client

Slide 31

Slide 31 text

Model as a Bento Cache Database

Slide 32

Slide 32 text

Model as a Bento Preferences

Slide 33

Slide 33 text

Model as a Bento Model Interface

Slide 34

Slide 34 text

Model as a Bento Main Thread Worker Thread

Slide 35

Slide 35 text

Model as a Bento

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

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

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

Bento and Clean Architecture Clean Architecture: Data Layer using Repository Pattern Bento

Slide 43

Slide 43 text

Don’t touch Bento directly Activity Activity Activity I want a healthy one! I want no-smelling one! I want one with !

Slide 44

Slide 44 text

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

Slide 45

Slide 45 text

Domain layer Activity Activity Activity Domain Domain Domain

Slide 46

Slide 46 text

Domain layer Activity Activity Activity

Slide 47

Slide 47 text

Domain layer Activity Activity Activity Filter out smelling foods

Slide 48

Slide 48 text

Domain layer Activity Activity Activity Filter out unhealthy foods

Slide 49

Slide 49 text

Domain layer Activity Activity Activity +

Slide 50

Slide 50 text

Domain layer Clean Architecture: 3 layer architecture

Slide 51

Slide 51 text

Domain layer Activity Activity Activity Clean Architecture: 3 layer architecture

Slide 52

Slide 52 text

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

Slide 53

Slide 53 text

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