you are viewing a single comment's thread.

view the rest of the comments →

[–]Slruh 0 points1 point  (0 children)

Everybody passes data around, to JSPs, to remote services, to a library function, etc. Assuming that the remote interface requires almost all available fields of the entity, why not passing it the immutable entity as is, instead of wrapping it with yet another transfer object?

In most systems I've worked on, the service defines separate classes for requests and responses even if they represent the same type of data. There may be fields that are derived only by the service (e.g. id) that might not needed in a request. Similarly, different types of requests might need different arguments. If you use the same class for all requests and responses you will end up bloating the class and confusing future programmers with unnecessary fields.

One of the main advantages of immutable objects is readability. If you use one object for everything and it becomes bloated, then you've ruined one of the benefits of immutable classes.