NextPrevUpTopContentsIndex

4.1.1 IDL for the account interface

We begin with the IDL definition of the interface to an account object.

// in module BankingDemo 
interface account { 
  readonly attribute string name; 
 
  readonly attribute long balance; 
 
  void credit (in unsigned long amount);
 
  exception refusal {string reason;}; 
  void debit (in long amount) 
    raises (refusal); 
}; 

The name of an account is recorded in its name attribute. The state of an account is recorded in its balance attribute. To keep things simple, we use CORBA long values to represent monetary amounts.

To prevent clients from directly altering the account's name or balance, these attributes are declared as readonly attributes. The operations credit and debit are provided to allow updates to an account's balance attribute.

The operation credit adds a non-negative amount to the current account balance.

Next comes an exception declaration:

exception refusal {string reason;};

This declares a named exception, refusal , that the debit operation uses to signal errors. The refusal exception is declared to contain a reason field that documents the reason for failure in the form of a string .

The operation debit subtracts a given amount from the current balance, provided doing so does not make the account balance negative. Qualifying debit by the phrase

raises (refusal)

declares that invoking this operation may raise the exception refusal . Although a CORBA operation may raise any CORBA system exception, its declaration must specify any additional user-defined CORBA exceptions that it might raise.

This completes the IDL declaration of the account interface.


Developing Component Software with CORBA - 30 Oct 2007

NextPrevUpTopContentsIndex