Hi all,
I'm still fairly new to DDD but I'm working through it. What I am
trying to understand is when methods appear in Entities and when Services.
For example if we take the following scenario:
In a shopping web site you can set up an account and buy things on
credit. You then have to make payments off of the account. To do
this the customer logs on and navigates to make payment where they
enter their credit details.
A payment comes back with a result.
* NOTE: This is another issue. MakePayment() is a command yet it
needs to return the result of the command.
Now this is where the domain and infrastructure cross and services vs
entities becomes a little complex (for me). The account is owned by
another system and the provider to make payments is owned by another
system. The result of making a payment can happen in a few days time
as the banking system itself works through and eventually tells the
account to change its balance.
How should this be modelled in DDD? Before DDD I just had a
PaymentService with a MakePayment(payment) method and that was that!
Some ideas I've had are along the lines:
class ApplicationService
{
private Account accountBeingAccessed;
public Result ProcessPaymentOnCurrentAccount(IPaymentDetails
paymentDetails)
{
IPaymentRequest paymentRequest =
accountBeingAccessed.CreatePaymentRequest(paymentDetails);
PaymentResult result = IPaymentServices.ProcessPayment(paymentRequest);
accountBeingAccessed.AddPaymentResult(result);
return result;
}
}
And the IPaymentServices should exist in the domain but be implemented
in the infrasturcure layer.
Does the above sound correct or is it more correct to say:
Account.ProcessPayment(IPaymentDetails);
PaymentResult result = Account.GetResult(IPaymentDetails);
And the account entity acceses the service which is again implemented
in the infrastructure layer?