Programming and Data Types    

Example -- Defining saveobj and loadobj for Portfolio

In the section Example -- The Portfolio Container, portfolio objects are used to collect information about a client's investment portfolio. Now suppose you decide to add an account number to each portfolio object that is saved. You can define a portfolio saveobj method to carry out this task automatically during the save operation.

Suppose further that you have already saved a number of portfolio objects without the account number. You want to update these objects during the load operation so that they are still valid portfolio objects. You can do this by defining a loadobj method for the portfolio class.

Summary of Code Changes

To implement the account number scenario, you need to add or change the following functions:

New Portfolio Class Behavior

With the additions and changes made in this example, the portfolio class now:

  Saving and Loading Objects The saveobj Method