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:
*Properties*:
TransactionType(Debit/Credit)
Amount
DateTime
2. Account
*Properties*:
Id
List<Transaction>
*Methods*:
withdraw
deposit
3. Customer
*Properties*:
Id
Name
List<Account>
4. Bank
*Properties*:
List<Customer>
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)
Problem: 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:
- Pass in
customerIdandaccountIdtodepositmethod ofDepositService, thenDepositServicegetCustomerobject and then getAccountobject from thatCustomerobject. - Keep List of
AccountsinBankclass instead of list ofCustomerand getAccountdirectly from this list and deposit amount. But in this case where to maintain customer list? BecauseAccountwould have customerId in that case and notCustomerobject. Now I need to keep map ofcustomerIdandCustomerobject but where to keep this map?
What could be better way to solve this problem?
Aucun commentaire:
Enregistrer un commentaire