0
0
Android Kotlinmobile~10 mins

Use cases / Interactors in Android Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a use case class with an invoke operator function.

Android Kotlin
class GetUserNameUseCase {
    operator fun [1](): String {
        return "Alice"
    }
}
Drag options to blanks, or click blank then click option'
Ainvoke
Bexecute
Crun
Dcall
Attempts:
3 left
💡 Hint
Common Mistakes
Using a regular function name like execute instead of invoke.
2fill in blank
medium

Complete the code to inject a repository into the use case constructor.

Android Kotlin
class GetUserAgeUseCase(private val [1]: UserRepository) {
    operator fun invoke(): Int {
        return repository.getAge()
    }
}
Drag options to blanks, or click blank then click option'
Arepo
BuserRepo
CuserRepository
Drepository
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatch between constructor parameter and usage name.
3fill in blank
hard

Fix the error in the use case function to return the user email from repository.

Android Kotlin
class GetUserEmailUseCase(private val repository: UserRepository) {
    operator fun invoke(): String {
        return repository.[1]()
    }
}
Drag options to blanks, or click blank then click option'
Aemail
BfetchEmail
CgetEmail
DretrieveEmail
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name that does not exist in the repository.
4fill in blank
hard

Fill both blanks to create a use case that returns true if user is active.

Android Kotlin
class IsUserActiveUseCase(private val [1]: UserRepository) {
    operator fun [2](): Boolean {
        return [1].isActive()
    }
}
Drag options to blanks, or click blank then click option'
Arepository
Binvoke
CuserRepo
Dexecute
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent parameter names or function names.
5fill in blank
hard

Fill all three blanks to define a use case that takes a userId and returns user details.

Android Kotlin
class GetUserDetailsUseCase(private val [1]: UserRepository) {
    operator fun [2](userId: [3]): User {
        return [1].getUserById(userId)
    }
}
Drag options to blanks, or click blank then click option'
Arepository
Binvoke
CInt
DString
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong parameter names or wrong userId type.