12.3. Exports

The Rentals in Sam's system are kept in RentalCollection. The information in Rental objects is used to produce the MultipleRentalDTO shown in the previous section, as well as the late return reports. If Sam wants to analyze the rentals for sales purposes, either analysis code has to be added to the system or the data has to be exported to an analysis program, such as SAS.

In keeping with the "Do a Little Job Well and You May Be Called Upon Often" guidelines, you should prepare systems to export data to and import data from other systems, such as analysis or accounting packages. Data can be exported periodically (snapshot) in standard formats for use in other systems. The export format can be XML, comma-delimited files, or some custom format. Data could also be made available in real time, as in an online ordering system that queries an inventory system for current availability of an item and notifies the inventory system when the order is placed.

We can use existing facilities of the underlying database to perform an export. Alternatively, we can create our own export methods. To demonstrate the alternative, for Sam's system we use export methods. There are two approaches to designing the export methods. We can use the existing methods in a class such as RentalCollection to retrieve a single Rental or a group of Rentals. Then we can create an interface that exports these Rentals (see Example 12-3).

Example 12-3. Export interface with groups of Rentals
 interface ...

Get Prefactoring 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.