Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Is it Ok if Domain Object cross Service-Boundary?

Everyone recommend that only DTO should be returned by Services. I am creating simple CRUD application.

Is it ok if my service methods return Domain object instead of flat DTO objects. It will save me from lots of mapping related setup. Is there any alternative approach?

share|improve this question
2  
There is not some DDD police that come up and break your hands when you violate some principle. I'm just sayin' –  Wyatt Barnett Aug 27 '12 at 13:04
2  
If you're really doing a simple CRUD application, I don't think you need all those DDD principles. –  Kristof Claes Aug 27 '12 at 13:17

1 Answer 1

up vote 6 down vote accepted

Martin Fowler states the first rule of distributed object design is: Don't distribute your objects!

It's understandable that you don't want to write mapping code to map from Domain to DTO and vice versa. Especially, because initially their data might be same. But doing so you couple the domain model to all the clients of the service. Changing your domain becomes impossible without breaking all the clients.

In .NET there is a library called AutoMapper to help mapping between objects. Other languages probably have similar tools.

share|improve this answer
    
+1 for this answer, but just for fairness Automapper is not the only tool available for this job :) –  MattDavey Aug 27 '12 at 19:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.