//ATM Simulation Interface - Individual Transactions

ATM Simulation Interface - Individual Transactions

/*
 * Example ATM simulation - file transaction.h
 *
 * This file declares the classes that represent the various kinds of
 * transactions that the ATM can perform.  The class Transaction serves as
 * an abstract base class for the other classes.  Each concrete class
 * basically serves to implement the corresponding use case.
 *
 * Copyright (c) 1996 - Russell C. Bjork
 *
 */


//

Interface for class Transaction

class Transaction
  {
    /*
     * PURPOSE: Serve as base class for specific types of transactions
     */

    public:

	Transaction(Session & session);

	// This value is returned by the keyboard to specify the particular
	// type of transaction the customer chose

	enum TransactionType
	  { WITHDRAWL, DEPOSIT, TRANSFER, INQUIRY };

	// Create a transaction object of a specified type, acting on behalf
	// of the specified session

	static Transaction * makeTransaction(TransactionType type,
					     Session & session);

	// Perform a particular transaction use case.  The card number and
	// PIN are obtained from the session; other information is obtained
	// from the customer

	void doTransactionUseCase();

	// Individual steps in carrying out a transaction.  Each must be
	// implemented individually for each type of transaction.  If
	// either of the first two steps returns in failure, the transaction 
	// is aborted.

	virtual bool getTransactionSpecificsFromCustomer() = 0;
	virtual Bank::ApprovalCode sendToBank() = 0;
	virtual void finishApprovedTransaction() = 0;

    protected:

	Session &	_session;

	// Every transaction is assigned a unique serial number that is used
	// to identify it in communications with the bank and on the receipt.

	int		_serialNumber;

	// Every transaction gets both the updated balance and available
	// balance for printing on the receipt.

	Money		_newBalance,
			_availableBalance;

    private:

	static int	_lastSerialNumberAssigned;
  };

//

Interface for class WithdrawlTransaction

class WithdrawlTransaction : public Transaction
  {
    public:

	WithdrawlTransaction(Session & session);

	bool getTransactionSpecificsFromCustomer();
	Bank::ApprovalCode sendToBank();
	void finishApprovedTransaction();

    private:

	Bank::AccountType	_fromAccount;
	Money			_amount;
  };

//

Interface for class DepositTransaction

class DepositTransaction : public Transaction
  {
    public:

	DepositTransaction(Session & session);

	bool getTransactionSpecificsFromCustomer();
	Bank::ApprovalCode sendToBank();
	void finishApprovedTransaction();

    private:

	Bank::AccountType	_toAccount;
	Money			_amount;
  };

//

Interface for class TransferTransaction

class TransferTransaction : public Transaction
  {
    public:

	TransferTransaction(Session & session);

	bool getTransactionSpecificsFromCustomer();
	Bank::ApprovalCode sendToBank();
	void finishApprovedTransaction();

    private:

	Bank::AccountType	_fromAccount,
				_toAccount;
	Money			_amount;
  };

//

Interface for class InquiryTransaction

class InquiryTransaction : public Transaction
  {
    public:

	InquiryTransaction(Session & session);

	bool getTransactionSpecificsFromCustomer();
	Bank::ApprovalCode sendToBank();
	void finishApprovedTransaction();

    private:

	Bank::AccountType	_fromAccount;
  };

//