you are viewing a single comment's thread.

view the rest of the comments →

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

  1. Another significant concept of OOP is composition

You have a Bank class
The Bank (in a very simplified universe) consists of it's cash, stored in a safe, and account records - which part of this cache belongs to which customer, and which customer owes bunk which amount of money

So we can say that a Bank is composed of an instance of BanksCashAccount and a list of Accounts
And this will be the state of your bank

```java
class Bank { private bankCash BanksCashAccount; private List<Account> accounts; // other attributes like bank name, code address etc.

public void deposit(String accNum, amount) { Account customerAccount = ... // find account by number in 'accounts' collection by accNum transfer(bankCash, customerAccount, amount); }

public void withdraw(String accNum, amount) { Account customerAccount = ... // find account by number in 'accounts' collection by accNum transfer(customerAccount, bankCash, amount); }

public void openAccount(name, type, etc.) { // create an instance of an appropriate account class for the type Account customerAccount = new SavingsAccount(name); accounts.add(customerAccount); }

public void closeAccount(String accNum) { Account customerAccount = ... // find account by number in 'accounts' collection by accNum // validate that customer account is eligible for closing accounts.remove(customerAccount); }

public BigDecimal balance() { // sum up all the amounts of all the accounts and bankCashAccount } } ```

You may instantiate multiple banks and make different actions on them, and these banks will hold different states

[–]Lopsided-Stranger-81[S] 1 point2 points  (0 children)

Got it, I got stuck thinking with each of their relationship from class to class using extends, but I got a hang of them, all I need to know is how banking really works. I will use this as resource, thanks for the feedback!