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: 247

We have a SOA-based system. The service methods are like:

  1. 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:

  1. Get parameters from UI (user)
  2. Create an instance of the Entity, using those parameters
  3. Get the entity from service
  4. Write code to fill the unchanged properties
  5. 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:

  1. ChangeUserPassword(int userId, string newPassword)
  2. AddEmailToUserAccount(int userId, string email)
  3. ChangeProfilePicture(int userId, Image image)
  4. ...

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

Related posts about programming-practices

Related posts about advice