rayworks
rayworks

Reputation: 796

DDD in Android app : communication between aggregate and application service

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.

Upvotes: 0

Views: 530

Answers (1)

rayworks
rayworks

Reputation: 796

According to the email with @islandcoder876

I generally run my CRUD operations through a repository.

Here’s the flow: Pass user info to application layer > application layer construct the user model from the info > application layer call update method on the repository located in the infrastructure layer > repository run the necessary network call to send the user info to the backend.

U can send the entire user object or just the fields u want to update.


Anemic domain model is not as bad as it seems, there are arguments for and against it. Methods on domain models are normally business rule specific, I don’t think changing name is a business rule, that’s just a crud operation.

I would say don’t complicate it by trying to make it fit into strict domain expectations. You won’t break anything with anemic models.

Upvotes: 0

Related Questions