Name

Data Transfer Hash

Goal

Reduce coupling between objects communicating via DTOs (Figure B-1).

Data transfer hash classes
Figure B-1. Data transfer hash classes

Participants

Business objects

Create hashes for sending data, or use values in received hashes.

Data transfer hash

Stores data for transport between layers as a set of values associated with well-known keys.

Presentation tier objects

Create hashes for sending data, or use values in received hashes.

Interactions

A presentation tier object requests data from the business tier. The business object reads the data, and inserts the values into a hash table with well-known keys for transport. The presentation tier object retrieves the data in the received hash by key. The presentation tier object modifies the received hash or creates a new one to transport data back to the business tier.

Notes

Data transfer hashes may be implemented as simple hash tables (or HashMaps). A more robust implementation uses a container object to hold the hash, as well as identifying information, type-safe data retrieval methods, and well-known keys.

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.