Should I modify an entity with many parameters or with the entity itself?
Posted
by
Saeed Neamati
on Programmers
See other posts from Programmers
or by Saeed Neamati
Published on 2012-06-24T12:03:01Z
Indexed on
2012/06/24
15:24 UTC
Read the original article
Hit count: 282
We have a SOA-based system. The service methods are like:
UpdateEntity(Entity entity)
For small entities, it's all fine. However, when entities get bigger and bigger, to update one property we should follow this pattern in UI:
- Get parameters from UI (user)
- Create an instance of the Entity, using those parameters
- Get the entity from service
- Write code to fill the unchanged properties
- Give the result entity to the service
Another option that I've experienced in previous experiences is to create semantic update methods for each update scenario. In other words instead of having one global all-encompasing update method, we had many ad-hoc parametric methods. For example, for the User
entity, instead of having UpdateUser (User user)
method, we had these methods:
ChangeUserPassword(int userId, string newPassword)
AddEmailToUserAccount(int userId, string email)
ChangeProfilePicture(int userId, Image image)
- ...
Now, I don't know which method is truly better, and for each approach, we encounter problems. I mean, I'm going to design the infrastructure for a new system, and I don't have enough reasons to pick any of these approaches. I couldn't find good resources on the Internet, because of the lack of keywords I could provide. What approach is better? What pitfalls each has? What benefits can we get from each one?
© Programmers or respective owner