https://kotlinlang.org logo
#android
Title
# android
m

Mohammed Oucif

03/04/2024, 9:30 AM
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

Robert Williams

03/04/2024, 10:37 AM
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

Andrew Carrell

03/04/2024, 2:19 PM
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.