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

, ,

Migrating to Jetpack Compose – an interop love story

Most of you are familiar with Jetpack Compose and its benefits. If you’re able to start anew and create a Compose-only app, you’re on the right track. But this talk might not be for you…
Watch Video

Migrating to Jetpack Compose - an interop love story

Simona Milanovic
Android DevRel Engineer for Jetpack Compose
Google

Migrating to Jetpack Compose - an interop love story

Simona Milanovic
Android DevRel Engin ...
Google

Migrating to Jetpack Compose - an interop love story

Simona Milanovic
Android DevRel Engineer f ...
Google

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
I’m not going to explain how important Clean Architecture or Hilt are, there are…
READ MORE
blog
There are many people who have shared their own versions of use case implementations,…
READ MORE
blog
Hey! It’s been a while since my last post, but the time has come…
READ MORE
blog
Now, let’s delve deeper into the process of making our use cases more fluent…
READ MORE

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

Menu