Suppose i have a use case "Customer Deposits Money on Account". Where should the functionality "Deposit()" go ? Customer or Account?. What should be the design for this use case ?
-
1Each customer can have an account associated with it. Depositing is an action taken by the customer, so this function/method should go there I think. – Tim Biegeleisen Feb 07 '17 at 05:19
-
I have one customer multiple accounts scenario. So i plan to design like this: Class Customer{ IList
accountList; deposit(IAccount account,amount) { //validate if account exists in accountlist here account.deposit(amount); } is this ok ? – aspxsushil Feb 07 '17 at 05:22
1 Answers
When a deposit
action is performed then this action records atleast the deposit_amount
and deposit_date
on which the action was done. So, placement of this action deposit
depends upon the following four scenarios (or relation between customer
and account
):
[1] An account
can belong to many customer
. However, a customer
can have a single account
. That is, the relation is one-to-many from account
to customer
. In such a case, deposit
(deposit_amount
and deposit_date
) action should be part of customer
.
[2] A customer
can hold many account
. However, an account
can belong to single customer
. That is, the relation is one-to-many from customer
to account
. In such a case, deposit
(deposit_amount
and deposit_date
) action should be part of account
.
[3] Many account
can belong to a single customer
. Also, an account
can be hold by many customer
. That is, the relation is many-to-many from account
to customer
. In such a case, it will be better to have a separate class CDeposit{
customer_id, account_id, deposit_amount, deposit_date}which will record this action
deposit`.
[4] An account
can belong to only one customer
. Also a customer
can hold only one account
. That is, the relation is one-to-one from account
to customer
. In such a case, deposit
(deposit_amount
and deposit_date
) action can be part of any of account
or customer
.

- 2,209
- 1
- 12
- 13