I'm trying to apply domain driven design
in an Android project. There is a common use case that the User
wants to change his/her name and this new name should be synced with backend.
class User {
// ...
fun changeName(newName:String, service: AccountService) {
val changed = service.changeName(newName)
if (changed) {
name = newName
}
// fire UserNameChanged event
}
}
As above code snippet shows, can I inject an application service to do the synchronization with Backend, or there is a better way to do it ? Thanks in advance.