views:

192

answers:

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!

+1  A: 

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.

flesh
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
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
@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