I'm worried I'm adding too many interfaces

前端 未结 3 1007
别跟我提以往
别跟我提以往 2021-02-12 09:30

I am building out my domain model and continuing to refactor it. As I do, I am finding that I like interfaces as it allows me to create reusable methods/controllers/views for c

3条回答
  •  失恋的感觉
    2021-02-12 10:19

    I think your problem is that you are trying to shoe-horn your domain model into whatever gui that you're displaying data in.

    Instead, consider your domain object things that have behaviour close to data and in its c'tor, give it an Action. Now, make sure that you ONLY EVER pass data OUT from a domain object through this action.

    Now, you listen. Whenever you actually want to make a change to your domain, call a method on it. Let your GUI be updated through the Action by taking these events and saving them to whatever read model that you are interested in.

    Have a look at http://www.infoq.com/presentations/ffffd-eric-evans and consider his points about domain events.

    Now you don't have to add strange interfaces related to a technical domain into your business domain anymore. And remember; if you are doing CRUD like your examples show, then you are NOT doing domain driven design. You have an anemic domain.

    Final point: use interfaces for things that actually need to be interchangeable. Are you carrying around a lot of INamed things in your application that can be interchanged with one another?

    Let me also link this, for you to consider:

    • http://lostechies.com/jimmybogard/2011/10/11/event-sourcing-as-a-strategic-advantage/
    • http://lostechies.com/jimmybogard/2010/04/08/strengthening-your-domain-domain-events/

提交回复
热议问题