-1

Using MVVM architecture in android, what is the best way to address cross cutting concerns.


E.g.

  • Showing a login screen if required even when screen wake up, having been in background for a long time.
  • Handling error from server.
  • Check if authenticated before creating an activity.
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Dino
  • 1
  • 1

2 Answers2

0

Well for the first one peobably use service and broadcast recievers. For handling error my advice is use rxjava .

For the third one simple use a global eventbus that way you can implement different approaches.

user8024871
  • 71
  • 1
  • 7
0

I don't think MVVM necessarily represents your cross-cutting concerns directly per se. Typically your ViewModel deals with your business logic, aka core concerns. However, you would have your cross-cutting concerns scattered through your different layers (Model, View, ViewModel).

For example, say you have a logging aspect to your application (a cross-cutting concern). This logger would then be injected as a dependency into your ViewModel to maybe log events. Or another example would be your networking functionality represented by an HTTP client is injected into your Model layer so you can make REST API calls. These cross-cutting concerns or dependencies can be scoped to the lifetime of your application since they're used ubiquitously.

It might be helpful for you to use Dagger to create these dependencies with an application scope.

TLDR: MVVM helps with separation of concerns, but you should compose your classes with your cross-cutting concerns/dependencies appropriately with dependency injection.

D Ta
  • 864
  • 6
  • 17