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
customerId
andaccountId
todeposit
method ofDepositService
, thenDepositService
getCustomer
object and then getAccount
object from thatCustomer
object. - Keep List of
Accounts
inBank
class instead of list ofCustomer
and getAccount
directly from this list and deposit amount. But in this case where to maintain customer list? BecauseAccount
would have customerId in that case and notCustomer
object. Now I need to keep map ofcustomerId
andCustomer
object but where to keep this map?
What could be better way to solve this problem?
Aucun commentaire:
Enregistrer un commentaire