Should an Aggregate Root Implement an Interface in Domain-Driven Design

前端 未结 2 1500
心在旅途
心在旅途 2021-01-18 04:55

I\'m working on a project using both domain-driven design and test-driven development. While reading through the DDD book by Evans, I noticed that he did not define interfa

2条回答
  •  情歌与酒
    2021-01-18 05:24

    I'm used to define interfaces for all entities and domain services to ease the test of clients using the domain. Moreover such approach ease AOP when required.

    As for value objects, it depends. For example I don't use interfaces for event arguments, identifiers, exceptions (obviously) and some other kind of "contracts". However, I had to introduce interface to ease the isolation of client code testing. Thus my rule of thumbs is: how many step the client require to get the value object in the desired state? If it's more than one (or two, good sense is my friend :-D), I introduce an interface from the very begining.

    Note I'm not talking about aggregates, since all my aggregates are entities too.

提交回复
热议问题