Contract -- interface

account

  class account {
  public:
  account();
  // assert( invariant() );
  
  virtual float balance() { return _balance; }
  
  void deposit(float x); 
\c{// to deposit money}
// require( x >= 0 ); // promise( balance() == old_balance + x && invariant() ); void withdraw(float x);
\c{// to withdraw money}
// require( x <= balance() ); // promise( balance() == old_balance - x && invariant() ); bool invariant() { return balance() >= 0; } protected: float _balance; };

slide: The $account$ contract

The interface for the account class given in slide 3-acc-1, specifies in an abstract way what the user expects of an account. From the perspective of design, the behavioral abstraction expressed by the axioms is exactly what we need, in principle. The implementation must guarantee that these constraints are met.