CodePark/ questions / Domain-driven design
START PRACTICINGPRACTICE
Backend question · Software design & patterns › Domain-driven design

Transferring money between two Account aggregates requires checking both balances and currencies. The logic belongs to neither account alone. Where does it go in DDD terms?

A domain service such as TransferService, stateless and in the domain layer, called by an application service

A domain service holds domain logic that does not naturally belong to one entity or value object. It is written in domain terms and keeps no state.

"An application service that contains the transfer rules and also handles transactions and authorization" is tempting but wrong. The application service coordinates the use case:

• It loads the aggregates.

• It calls the domain service.

• It manages the transaction and authorization.


But it should not hold the business rules itself.