Share
Embed
Transcript
34 slides
-
What we learned • The mindset behind the clean architecture
• The dependency rule • Testability (the most important part) • Separation of concerns • Level of abstraction -
Clean Architecture Entities Use Cases Controllers Gateways Presenters Android W
eb UI External Interfaces DB -
Introducing Android Jetpack • Robust • Solve many known problems
• Being sold as a silver bullet • Kotlin friendly -
Kotlin • AndroidX • Kotlin Android Extension plugin • Replacement
of some famous annotation-based processing libraries such as Dagger, Butterknife, … • DSL (Gradle) • Functional (Arrow) • Coroutines -
Clean Architecture on Android • What happen when we implement
clean architecture on real productions? • YAGNI • Interactors act just as a proxy to a gateway • Do we really need abstraction? • Kotlin features instead of (some) abstractions • Redundant boilerplate • Most of the time, we’re dealing with platform specific concerns -
Clean Architecture on Android • MV ( ? ) •
Dagger Hype • Using Kodein and Koin with no more code get • RxJava Hype • RxJava vs Kotlin coroutines + kotlin operators vs LiveData • Memory consumption -
Clean Architecture on Android • Testing is forgotten because of
time: • Which MV(?) ? • Dagger or Koin? • RxJava or Coroutines? • Clean architecture boilerplate • And many other things … -
Clean Architecture on Android • Sometimes our platform specific codes
are not clean enough • Location and GPS modules • The logic inside Notification, Download manager, Background Job and … • Communication between these things and our data or presentation layer ——> Side effect on testing -
It’s not just about Architecture • Making an app contains
different criteria and concerns • Architecture must be aligned with testing • Architecture is to support the life cycle of the system -
There is no silver bullet • It always depends on
• Using Rx or Coroutines • Using interactors or not • Which test framework • …. -
Different components of an application Business Logic Decision Architecture Design
CI/CD Build System Cross-cutting Concern Test App Implementation SAST Platform Specific -
Android SDK, RxJava, Dagger, Robolectric, … Business Logic Decision Architecture
Design CI/CD Build System Cross-cutting Concern Test App Implementation SAST Platform Specific -
Logging, Analytics, Developer Settings …. Business Logic Decision Architecture Design
CI/CD Build System Cross-cutting Concern Test App Implementation SAST Platform Specific -
Download Manager, Job Scheduling, … Business Logic Decision Architecture Design
CI/CD Build System Cross-cutting Concern Test App Implementation SAST Platform Specific -
fastlane, gradle, lint, sonarqube , … Business Logic Decision Architecture
Design CI/CD Build System Cross-cutting Concern Test App Implementation SAST Platform Specific -
What we are going to do? • Aggregate all these
concerns • Making a multi-platform app • Mobile, Wear and TV • Based on TV Maze API • Clean + Kotlin + AAC + Test + CI/CD + Build system .…. • Available on Github ( SaeedMasoumi/MovieHub ) -
Our Stack • Kotlin • AAC, Leanback, Wearable • Koin
• Glide • (RxJava, Coroutines) Maybe ?! • Retrofit • Circle CI • Espresso, Robolectric , Mokk • Lint, Detekt, Ktlint, SonarQube, … • Developer Settings (Leak Canary, Logs, …) -
Modularity • Modularity is being popular • Different way to
modularize your app • Based on layer • Based on feature -
Business Logic • Identify our requirements • Create entities •
Create our domain layer (Repositories/Services, Interactors, …) • Create any other abstractions -
Business Logic data class TVShow( val id:Int, val name:String, val
summary:String, val schedule:Schedule, val tvNetwork: TVNetwork, val url:String //... ) -
Business Logic data class TVShow( val id: Int, val name:
String, val summary: String, val schedule: Schedule, val tvNetwork: TVNetwork, val url: String //... ) data class TVNetwork( val id: Int //... ) data class Schedule( val time: Date //... ) -
Business Logic interface TVShowRepository { fun getAllShows(): List<TVShow> } interface
FavoriteRepository { fun add(showId:Int): List<TVShow> } -
AAC on Wear public class MyActivity extends WearableActivity implements LifecycleOwner
{ private LifecycleRegistry mLifecycleRegistry; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mLifecycleRegistry = new LifecycleRegistry(this); mLifecycleRegistry.markState(Lifecycle.State.CREATED); } @Override public void onStart() { super.onStart(); mLifecycleRegistry.markState(Lifecycle.State.STARTED); } @NonNull @Override public Lifecycle getLifecycle() { return mLifecycleRegistry; } } -
AAC on TV public class SearchFragment extends android.support.v17.leanback.app.SearchSupportFragment implements android.support.v17.leanback.app.SearchSupportFragment.SearchResultProvider{
private VideosViewModel viewModel; @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); //TODO implement viewModel.getSearchResult().observe(…) } } -
Data <-> Remote & Local • Using datasources to switch
between sources • Decision goes into data layer • Room and DAOs goes into local layer (AKA cache, persistence, storage, …) • Retrofit goes into remote • Any other logics (e.g. Location) goes into data layer or if you need more modularity make a separate module -
Summary • AAC • Kotlin Features • Clean Architecture Revision
• Other aspects of Apps ( CI/CD, Test etc) • No Silver Bullet