Object Oriented Programming Style

  1. The object oriented style of programming require us to consider how an object behaves...

  2. Consider a bank account...

    Some of the operations that you can perform on a bank account are:

  3. To represent bank accounts, we define a BankAccount class.
    (So that we can create bank accounts objects)

    class BankAccount { ... what kind of variables ? ... what kind of methods ? }

  4. It is easier to determine the method first.

    Note that a method may have:

  5. To represent the operations allowed on bank accounts objects, we define methods inside the BankAccount class.

    class BankAccount { ... what kind of variables ? (later) ... deposit(double amount) // -- to deposit money into account { ... (later) } ... withdraw(double amount) // -- to withdraw money from account { ... (later) } ... getBalance() // -- to retrieve balance of account { ... (later) } }
    More on method definition very soon....


  6. ******* The methods in a class will define the behavior of the objects of that class.

  7. How to create a checking for Harry and a saving account for Mom:

    BankAccount harrysChecking = new BankAccount(); BankAccount momsSaving = new BankAccount();

  8. How the banking operations are performed on Harry's checking and Mom's saving accounts:

    harrysChecking.deposit(2000); -- deposit $2000 into Harry's checking account momsSaving.deposit(1000) -- deposits $1000 into Mom's saving account harrysChecking.withdraw(1500); -- withdraws $1500 from Harry's checking account momsSaving.withdraw(500) -- withdraws $500 from Mom's saving account System.out.println("Balance " + harrysChecking.getBalance(); -- prints Harry's checking account balance System.out.println("Balance " + momsSaving.getBalance(); -- prints Mom's saving account balance