Home » Java » java – What could be a better way to design bank application-Exceptionshub

java – What could be a better way to design bank application-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment


I have to create a bank application in OOP way that supports: Withdraw, Deposit, Maintain Transaction List.
I have come up with following class:

 1. Transaction:
 2. Account
 3. Customer
 4. Bank

Now to add customer and add account I have created CustomerService and AccountService respectively
And to withdraw and deposit I have created WithdrawService and DepositService(I could create TransactionService to include both)

Lets say user want to deposit $100

Client of DepositService ( e.g. controller in case of mvc) would call deposit method of this DepositService and would pass in AccountId
But I don’t have ready collection of Account objects to get Account object for this AccountId instead I have collections of Customers in Bank class. So I could not directly get Account object and deposit amount to it.
So I have come up with following ways:

  1. Pass in customerId and accountId to deposit method of DepositService, then DepositService get Customer object and then get Account object from that Customer object.
  2. Keep List of Accounts in Bank class instead of list of Customer and get Account directly from this list and deposit amount. But in this case where to maintain customer list? Because Account would have customerId in that case and not Customer object. Now I need to keep map of customerId and Customer object but where to keep this map?

What could be better way to solve this problem?

How to&Answers: