But, it is possible to change the representation of a handle at run-time. Changing the representation of a handle effectively changes the object's type. Suppose you are developing software for a large bank. The bank has many different kinds of accounts, including checking accounts, savings accounts, and money market accounts. Your task is to develop a program that reads in account balances from a database in order to initialize the objects for the program.
All accounts have an account identifier and a total balance.
Class BankAccount has a virtual constructor which examines the account identifier to determine what type of account is to be constructed. Virtual constructors can be used whenever the creation of an object must be delayed until run-time when some other context information is available to determine the object's type. In a future installment of this column, we will look at some more advanced uses of handles, including delegation and more dynamic ways to change an object's type at run-time. Addison-Wesley, Reading, Mass., 1992. Addison-Wesley, Reading, Mass., 1993.