[ Team LiB ] |
B.2 Data Transfer Patterns
GoalReduce coupling between objects communicating via DTOs (Figure B-1). Figure B-1. Data transfer hash classesParticipants
InteractionsA 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. NotesData 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.
GoalImprove performance by reducing the number of objects passed between tiers (Figure B-2). Figure B-2. Classes in the DTO patternParticipants
InteractionsA presentation tier object requests data from the business tier. The business object reads the data and copies it into a DTO for transport. The presentation tier object uses the data in the received DTO. The presentation tier object modifies the received DTO or creates a new one to transport data back to the business tier. NotesDTOs may be data objects used within the business objects themselves, or dedicated classes for transporting data. DTOs often follow JavaBean semantics, but this is not a requirement.
GoalMinimize overhead while transporting the results of a database query. Participants
InteractionsA presentation tier object requests data from the business tier. The business object performs a database query and stores the resulting rows and columns in a row set DTO for transport. The presentation tier object accesses the data in the received DTO as rows and columns. NotesIn many instances, it is easiest to simply send the JDBC ResultSet object directly to the client. When this is not desirable, a separate class implementing the ResultSet interface can be used, or a lighter-weight interface can be defined. |
[ Team LiB ] |