Java Reference
In-Depth Information
The following step enters code to create the serializeObj() and deserializeObj()
methods for the StockTrackerDB class.
To Serialize and Deserialize Objects
1. Enter lines 53 through 80 as shown in Figure 11-36 on page 734.
The methods, serializeObj() and deserializeObj(), display in the
StockTrackerDB class (Figure 11-40). They are identical to the methods
written earlier, except for being private.
serializeObj()
method
private
deserializeObj()
method
FIGURE 11-40
The StockTrackerDB class must provide functionality to manipulate three
tables, Users, Stocks, and UserStocks, while keeping the contents properly syn-
chronized. For example, deleting a user record from the Users table requires all
of the corresponding records for the user in the UserStocks table to be deleted.
Likewise, if the last UserStocks record for a particular stock is deleted, indicating
that no users hold this stock, then the corresponding stock must be deleted from
the Stocks table. Although the order in which these methods are created does not
matter, they should be arranged in a logical grouping that makes later mainte-
nance easier. This can be accomplished by locating together methods that use the
same table. If a method needs access to multiple tables, however, it might be dif-
ficult to determine where in the program to place the method. Generally, four
actions are typical with database programs: adding new records, updating exist-
ing records, deleting existing records, and obtaining a list of one or more selected
fields for one or more records. By grouping methods according to actions, rather
than tables used, the program is structured for ease of maintenance.
 
Search WWH ::




Custom Search