I want to (mass) update aggregate roots with data from a leading external system. To do so a scheduler runs a task which fetches updates for my existing objects and data for new objects from the remote system. Essentially I'm overriding the existing data, since the remote system is the leading system for master data. But the aggregate roots in my system will have properties that exist only in my system, so the aggregate root instances could not actually be overridden.
Is see several way to update an aggregate root in my case. One of the following methods could be part of my aggregate root class:
fun update(other: MyEntity)
fun update(field1: String, field2: String, field3: Double)
fun update(update: MyEntityUpdate)where
MyEntityUpdatewould be something like a DTO
My first thought was
fun update(other: MyEntity), but then I had to create an aggregate root instance, just to copy field by field into the object that should be updated. An advantage would be that the other entity would be valid, since validation logic in its constructor must have been executed. However, it would probably be the responsility of the
update method to ensure that the update is correct.
The second solution could be a bit ugly for long parameter lists, though it would be quite readable with Kotlins named parameters. The
update method would have to check all values explicitly, since they were not "pre validated" like in the first solution.
The third solution is basically the same as the second, but with the parameters packed in a
What do you think is the best approach? Are there other pros/cons? Or are there other solutions?