Part 1: Look and feel

 
 
 

1.1   Specification

        Read and show the balance of a bank account.
 
 

1.2   Analysis

        The balance is a REAL value stored in a class ACCOUNT.
 
 

1.3   Solution design

        Separate routines are used to read in, and to write out, the balance. The creation routine calls these routines. The get routine reads in a value from the user and stores it in the variable balance. The show routine writes the value of balance to the terminal screen. Class ACCOUNT is the root class for a system of one class, so the make routine calls every other routine in the class:
 

class ACCOUNT

feature
        balance: REAL

        make is
             do
                        get
                        show
             end -- make

        get is ...

        show is ...

end -- class ACCOUNT
 

        The creation routine can be used by any client, so it’s creation policy is ANY:
 

creation {ANY}
        make
 

        The attribute balance and the routines that get and show the attribute are private:
 

feature {NONE}
        balance ...

        get is ...

        show is ...
 
 

1.4   Client chart
 
 
 


 
 
 
 

1.5   Ace file

        The Ace file to compile this system of one class is shown below. The name of the executable file is bank. The name of the root class is ACCOUNT. The name of the creation routine in the root class is make.

        The system uses a precompiled set of Eiffel classes, and three clusters that contain files to be compiled. The current directory ("/") contains the user-defined class ACCOUNT. Two Eiffel library directories are used to compile the system, the kernel directory and the support directory.
 

system
        bank

root
                ACCOUNT: "make"

default
        assertion (require);
        precompiled ("$EIFFEL3/precompiled/spec/$PLATFORM/base")

cluster
            eiffel: "./";
            kernel: "$EIFFEL3/library/base/kernel";
            support: "$EIFFEL3/library/base/support";

end
 
 

1.6   Solution code
 

class ACCOUNT

creation {ANY}
        make

feature {NONE}
        balance: REAL

        get_balance is
                     -- read the initial account balance, store it
            do
                        io.putstring (" Initial account balance: $")
                        io.readreal
                        balance := io.lastreal
            end -- get_balance

        show_balance is
                     -- show the balance
            do
                        io.putstring ("%NThe balance is $")
                        io.putreal (balance)
            end -- show_balance

feature {ANY}
        make is
                     -- use the account
            do
                        get_balance
                        show_balance
            end -- make

end -- class ACCOUNT