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


    Kotlin Multiplatform Mobile Developer

    Touchlab
    Remote
    • Full Time
    apply now

    Sr. Software Development Engineer, Last Mile Driver Assistance Technology

    Amazon
    Berlin
    • Full Time
    apply now

OUR VIDEO RECOMMENDATION

,

Luis Tsai & Ayushi Gupta

Listen to droidcon Berlin 2022 conversations with Madonna & Matt up next Luis Tsai & Ayushi Gupta.
Watch Video

Droid-Conversations

with Madona & Matt

Luis Tsai & Ayushi Gupta

Droid-Conversations

with Madona & Matt

Luis Tsai & Ayushi Gupta

Droid-Conversations

with Madona & Matt

Luis Tsai & Ayushi Gupta

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
Hey! It’s been a while since my last post, but the time has come…
READ MORE

Leave a Reply

Your email address will not be published.

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

Menu