J.9. Class transactionClass transaction (Fig. J.8) is an abstract base class that represents the notion of an ATM transaction. It contains the common features of derived classes BalanceInquiry, Withdrawal and Deposit. This class expands upon the "skeleton" code first developed in Section 11.8. Line 3 declares this class to be MustInherit (the Visual Basic equivalent of an abstract class). Lines 46 declare the class's Private instance variables. Recall from the class diagram of Fig. 11.20 that class transaction contains an property AccountNumber that indicates the account involved in the transaction. Line 4 implements the instance variable accountNumberValue to maintain the AccountNumber property's data. We derive attributes screen (implemented as instance variable screenHandle in line 7) and bankDatabase (implemented as instance variable bankDatabaseHandle in line 8) from class transaction's associations modeled in Fig. 11.19. All transactions require access to the ATM's screen and the bank's database. Figure J.8. MustInherit base class transaction represents an ATM transaction.
Class transaction has a constructor (lines 914) that takes the current user's account number and references to the ATM's screen and the bank's database as arguments. Because TRansaction is a MustInherit class (line 3), this constructor will never be called directly to instantiate TRansaction objects. Instead, this constructor will be invoked by the constructors of the transaction derived classes via MyBase.New. Class transaction has three Public ReadOnly propertiesAccountNumber (lines 1721), ScreenReference (lines 2428) and BankDatabaseReference (lines 3135). Derived classes of transaction inherit these properties and use them to gain access to class TRansaction's Private instance variables. Note that we use the word "Reference" in the names of the ScreenReference and BankDatabaseReference properties for claritywe wanted to avoid property names that are the same as the class names Screen and BankDatabase, which can be confusing. Class TRansaction also declares a MustOverride method Execute (line 38). It does not make sense to provide an implementation for this method in class TRansaction, because a generic transaction cannot be executed. Thus, we declare this method to be MustOverride, forcing each transaction derived class to provide its own concrete implementation that executes the particular type of transaction. |