Blog Infos
Author
Published
Topics
,
Published
The Theory

Example of use case vs. domain “model”

The Implementation
class SignInUseCase {
  suspend fun signInWithEmail(email: String, password: String): User {
    ...
  }
  suspend fun signInWithGoogle(serverAuthCode: String?): User {
    ...
  }
}

vs.

class SignInWithEmailUseCase {
  suspend fun signIn(email: String, password: String): User {
    ...
  }
}
class SignInWithGoogleUseCase {
  suspend fun signIn(serverAuthCode: String?): User {
    ...
  }
}

Either you have two functions in one class or two classes with one function. Both describe the same interaction of the same actor (the user signing in). In my opinion, there are situations when there is no major advantage to using one option over another, or to combining both. The final decision regarding which way to go should most often be based on the size and structure of the project, the complexity of the implemented logic or just preferences of the coding conventions a team has established.

A use case object does not have to contain just one function, as long as it encapsulates one functionality.

                  UML sketch, I have not mastered it ¯\_(ツ)_/¯

Job Offers

Job Offers

There are currently no vacancies.

OUR VIDEO RECOMMENDATION

No results found.

Jobs

Composition
class ViewProfileUseCase(
  private val dataSource: DataSource
) {
  suspend fun getUserProfile(): User {
    return dataSource.getCurrentUser()
  }
}

“Change password” use case allows the user to change the password if the provided current password matches the actual one.

class ChangePasswordUseCase {
  suspend fun changePassword(current: String, new: String): User {
    ...
  }
}

Source: https://cz.pinterest.com/pin/704602304185711164/

Resources:

 

YOU MAY BE INTERESTED IN

YOU MAY BE INTERESTED IN

blog
Today I aim to cover the Domain layer. It is a layer that sits…
READ MORE
blog
I’m not going to explain how important Clean Architecture or Hilt are, there are…
READ MORE
blog
In the previous article about app architecture, I covered how to build your Domain,…
READ MORE
blog
There are many people who have shared their own versions of use case implementations,…
READ MORE
Menu