How To Avoid Use Cases Boilerplate in Android

Exploring four different approaches — Since the dawn of layered...

Denis Brandi

September 6, 2022

1

min read

What if I tell you that you can remove all the boilerplate code of your use cases and avoid writing them when not needed without affecting your presentation layer?

No, I’m not joking! 😎

A while ago I wrote why you need use cases and what they are so in this article I’m not going to dig too much into details, if you are new to them I suggest you read my previous article before.

To summarize we can say that Use cases are an evolution of Application Services that bring the following benefits:

  1. Isolation of application logic (this was given by Application Services too)
  2. Adhesion to Interface Segregation Principle: for example, your ViewModel will have as collaborators only the needed Use cases and not a huge interface (either application service or repository if you are skipping the layer) with 10+ methods where only 1 or 2 are needed.
  3. Thinner Presenters/ViewModels
  4. Screaming Architecture: you know what the app does by looking at the use case names.