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

, ,

From Scoped Storage to Photo Picker: Everything to know about Storage

Persistence is a core element of every mobile app. Android provides different APIs to access or expose files with different tradeoffs.
Watch Video

From Scoped Storage to Photo Picker: Everything to know about Storage

Yacine Rezgui
Android developer advocate
Google

From Scoped Storage to Photo Picker: Everything to know about Storage

Yacine Rezgui
Android developer ad ...
Google

From Scoped Storage to Photo Picker: Everything to know about Storage

Yacine Rezgui
Android developer advocat ...
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
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. Required fields are marked *

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

Menu