I'm refactoring my desing to use a service layer - however I'm confused about how you would pass arguments, when it's only allowed to update certain fields of the entity. For instance I have some fields which are only allowed to be set at creation (meta data). But every examples I see about service layer takes the entity as argument, eg. update(Entity entity), where all the values possibly could have been changed. If I only want to make it possible to add orders (and not modifying anything else for the customer). This could be done by:
which looks very nice, however I could change other fields in the customer without this being noticed by the service. My alternative would by something like:
service.addOrder(customer, new Order())
This seems reasonable. However this could possibly create methods with very long parameterlists (bad) and also loading the same entity twice (both in servicelayer and in where it is used before). Would it be better to simply create DTO's and methods for every partial update of the entity? This would also require either the service layer or repository to load the (possibly) already loaded entity from the database.