DTO or Domain Model Object in the View Layer?

前端 未结 9 1992
再見小時候
再見小時候 2020-12-22 17:32

I know this is probably an age-old question, but what is the better practice? Using a domain model object throughout all layers of your application, and even binding values

9条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-22 18:03

    Another vote for domain objects. As far as Domain Driven Design is concerned the domain model is the king and should be used where possible. The application should be designed in a way where most layers (bar Infrastructure layer) can use domain objects.

    I think of DTOs as useful only where the objects need to be serialised. If there is no transfer over the wire or into an incompatible architecture I would not use them. DTO pattern is useful for keeping serialisation out of the domain object. Considering that UI/Domain interaction does not need serialisation, keep it simple and use the actual objects.

提交回复
热议问题