Next Previous Up Top Contents Index

4.1 Designing the IDL

4.1.1 IDL for the account interface

We begin with the IDL definition of the interface to anaccount 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 itsname attribute. The state of an account is recorded in itsbalance attribute. To keep things simple, we use CORBAlong values to represent monetary amounts.

To prevent clients from directly altering the account's name or balance, these attributes are declared asreadonly attributes. The operationscredit anddebit are provided to allow updates to an account'sbalance attribute.

The operationcredit 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. Therefusal exception is declared to contain areason field that documents the reason for failure in the form of astring.

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

raises (refusal)

declares that invoking this operation may raise the exceptionrefusal. 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 theaccount interface.


Developing Component Software with CORBA - 22 Jan 1999

Next Previous Up Top Contents Index

Generated with Harlequin WebMaker