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


    Android Developer

    Small and Modern GmbH
    Hamburg, Remote (Germany)
    • Full Time
    apply now

    Android Build Engineer

    Pinterest
    San Francisco, CA | Seattle, WA
    • Full Time
    apply now

    Senior Android Developer (Remote)

    Komoot
    Europe
    • Full Time
    apply now
Load more listings

OUR VIDEO RECOMMENDATION

,

Leveling Up Your Tests

We all know about TDD and Unit Testing, and even screenshot testing, but sometimes we do not need to embrace a new paradigm to make our tests better. These are several techniques I have adopted…
Watch Video

Leveling Up Your Tests

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
It’s one of the common UX across apps to provide swipe to dismiss so…
READ MORE
blog
In this part of our series on introducing Jetpack Compose into an existing project,…
READ MORE
blog
Nowadays authentication has become common in almost all apps. And many of us know…
READ MORE
blog
Collections are a set of interfaces and classes that implement highly optimised data structures.…
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