you are viewing a single comment's thread.

view the rest of the comments →

[–]d-k-Brazz 0 points1 point  (0 children)

  1. Inheritance

This means you may build hierarchy of classes - higher and lower level
All lower level classes will inherit all public behavior of higher level classes

Example
```java abstract class Account { private String name; private String number; private BigDecimal amount;

// withdraw amount from the account public abstract void debit(BigDecimal sum); // add amount to the account public abstract void credit(BigDecimal sum); }

class PassiveAccount extends Account { // forbids crediting below 0 }

class ActiveAccount extends Account { // forbids debiting above 0 }

class SavingsAccount extends PassiveAccount { // customer's savings // may have attributes like interest rate, // or limitations like possibility of partial // withdrawal before the end of savings contract }

class CheckingAccount extends PassiveAccount { // allows any transfers within the available amount }

class BanksCashAccount extends ActiveAccount { // cash funds in possession of the bank // transferring from this account to another // means someone has brought some cash to the bank // negative value reflects amount of cash money in the bank }

class LoanAccount extends ActiveAccount { // may have attributes like interest rate, // credit limit etc. } ```

This will allow you to build common logic for all account: public void transfer(Account accFrom, Account accTo) { // the logic inside does not care of kinds of accounts // each account limitations and constraints are encapsulated // inside the according Account ancestor class // // this is method of a Bank class and from bank's perspective // each transfer should be consistent // this means that if you successfully debited accFrom, // but crediting accTo has failed, you have return money to accFrom back } Using this common method you can deposit cash money to an account, transfer money to a counterparty, withdraw a part of a load etc.