<https://twitter.com/KotlinMumbai/status/139715682...
# feed
j
Are those UseCase really needed in the first place? Reminds me strongly of Steve Yegge's Execution in the Kingdom of Nouns http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html
s
It's just example to demonstrate
invoke()
. Rest, it depends on developers how they want to use it.
r
Nice one. I guess, you can also do
Copy code
AddUserUseCase()(1, "John Doe")
which seems fun 😄 Also! By having
Copy code
object AddUserUseCase {
  operator fun invoke(userId: Int, name: String) { ... }
}
you can then do
Copy code
AddUserUseCase(1, "JohnDoe")
People will think it's a constructor, but nope!
👍 1
s
👍 That's why it's mentioned, "Do not overuse it" 😅
j
@jmfayard it has one advantage, it lets you injects things, and if the use case is injected as argument in a ViewModel for example, the usage looks like a function.
👍 1
In an ideal world or if the DI you use allow it, the use case should be a function directly
j
Good points, I agree