Data Transfer Patterns
In an ideal world, every time we send data from one place to another, we would include all the information required for the current activity, with no waste and no need for the recipient to come back with questions. Anyone who has worked technical support is familiar with the situation: it’s much easier to have the user explain the entire problem at once, with all the relevant detail, rather than have to ask a series of questions to determine whether the computer is on, if an error message was displayed, if the software was actually installed, and so forth. A single support person can handle more problems with fewer headaches.[1]
In Java terms, this ideal could involve transferring a single object
containing a complete bug report, rather than transmitting several
individual objects for each aspect of the report. Of course, we still
have to deal with the trade-off between performance and flexibility.
When objects interact with each other in a local JVM, the overhead of
a method call is generally fairly small, while the overhead of
additional objects, both in terms of developer time and runtime
resources, can be fairly high. When dealing with a class representing
a person, it may make more sense to include a set of address fields
in the Person
class itself, rather than creating a
separate Address
class to hold address
information. The cost in code complexity of the additional fields may
be balanced by the need to manage fewer objects at runtime.[2]
Once remote ...
Get J2EE Design Patterns now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.