12.3. Exports

 <  Day Day Up  >  

The Rental s 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 Rental s. Then we can create an interface that exports these Rental s (see Example 12-3).

Example 12-3. Export interface with groups of Rentals
 interface RentalCollectionExport     String export_rentals_as_comma_delimited_text (Rental [] rental_list)     String export_rentals_as_xml(Rental [] rental_list) 

With this interface, first the user calls a search method in RentalCollection and then passes the resulting group to the export method. Example 12-4 shows the RentalCollectionExport interface.

Example 12-4. Using the RentalCollectionExport interface
 Rental [] to_export =     RentalCollection.retrieve_rentals_for_customer(a_customer); String output = RentalCollectionExport.     export_rentals_as_comma_delimited_text(to_export); 

Alternatively, the export interface can implement methods that matched the retrieval methods in RentalCollection . This alternative interface appears in Example 12-5.

Example 12-5. Export interface performing searches
 interface RentalCollectionExport     String export_rentals for_customer_as_xml(a_customer)     String export_rentals_for_customer_as_comma_delimited_text(         a_customer) 

These two alternatives represent a different form of the "Spreadsheet Conundrum." In Example 12-3, more ways to search Rental s can be added to RentalCollection without requiring any changes in RentalCollectionExport . In Example 12-5, existing mechanisms in the underlying database can be employed to export the data. If there were no database export mechanism, these methods would call the corresponding methods in RentalCollection . Adding new methods to search for Rental s to export would require additional methods to both classes.

In either case, the Rental data is made available to the other systems. These methods could be invoked by an ExportOperations interface, which in turn could be executed by an appropriately designed graphical user interface (GUI).

BE READY TO IMPORT AND EXPORT

Data should be available for use outside the system via a well-defined data interface .


 <  Day Day Up  >  


Prefactoring
Prefactoring: Extreme Abstraction, Extreme Separation, Extreme Readability
ISBN: 0596008740
EAN: 2147483647
Year: 2005
Pages: 175
Authors: Ken Pugh

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net