1

Is it possible to use DDD and a rich domain model if your application is like:

  • windows client (WPF)
  • windows service

And communication happens with WCF?

I'm used to have DTO's with only data state, and have business rules inside the Service layer, but everyone keeps telling me that I should have a rich domain model where data state and rules/methods are all in the objects themselves.

I'm just not sure if this rich domain model would apply to a system that has a UI and communicates via WCF to a service (like I presented above). In my case is it better to continue using an anemic domain model because of WCF? If not, could you please give an example on how to architecture it using a rich domain model, considering WCF, proxy, etc?

Thanks!

Name123
  • 25
  • 3

1 Answers1

3

Generally speaking you serialize your domain objects for transmission across WCF as some simplified DTO anyway, and it's these that are consumed by your client application.

You can serialize user defined types and deserialize them in the client but for most applications this is unnecessary. As long as you don't need the 'rich' behaviour of your objects in your client (which you shouldn't with a good DDD anyway), it sounds to me like you are fine to use a rich design in your service layer and send simple DTOs across the wire.

Community
  • 1
  • 1
flesh
  • 23,725
  • 24
  • 80
  • 97
  • Thanks flesh. In this case I would have duplicated definitions. For example, for User, I would have a User domain object (with data state and methods) and also a User DTO (with only data state). Is this a good or acceptable thing to do? Thanks – Name123 Nov 30 '09 at 20:54
  • Yes, that's fine. In fact, that is generally the kind of pattern you would use for supporting things like web services and smart client apps. I use similar patterns - passing state bags / DTOs for consumption in client and much richer models in the domain where it makes sense to encapsulate behaviour as well. – flesh Nov 30 '09 at 23:17
  • 2
    @flesh: "...As long as you don't need the 'rich' behaviour of your objects in your client (which you shouldn't with a good DDD anyway)...". That's a pretty harsh restriction! Are you suggesting that client PCs shouldn't execute logic? – Vijay Patel Dec 01 '09 at 10:45
  • 1
    Yes I don't get this either - what about validation logic? I want to have validation logic as part of my domain model, but it is also helpful to be able to apply this as a user is filling in a form. I don't want to duplicate this logic, but how else would it be shared if the UI only uses DTOs? – Stephen Drew Nov 20 '11 at 17:39