Hello everyone, I hope you are doing well. I am re...
# android
m
Hello everyone, I hope you are doing well. I am reading a book about Clean Architecture in Python and the idea of writing use-cases as functions caught my attention. In Android, we usually write all use-cases as classes but why don't we write them as functions if they are simple and require only one dependency to work properly (for example fetching data from an API with simple or no further processing) ?.
not kotlin but kotlin colored 3
r
You kind of get the best of both with functional classes, and this is already a pretty common pattern for use cases (e.g. here and here)
If you design use cases this way it's pretty much implementation detail whether the actual version is a raw function or a functional class
🙌 2
Although you might run into other problems if you try to use raw functions, especially if you use Dagger
a
Instead of using raw functions, you could write your use cases as fun interfaces, as in this article here: https://betterprogramming.pub/how-to-avoid-use-cases-boilerplate-in-android-d0c9aa27ef27 This would work for dependency injection frameworks as well.