Difference between Value Object pattern and Data Transfer pattern

后端 未结 8 1042
别跟我提以往
别跟我提以往 2021-01-31 23:01

In which scenario can I use those design patterns in n-tier architecture?

8条回答
  •  名媛妹妹
    2021-02-01 00:00

    DTO is a class representing some data with no logic in it. DTO’s are usually used for transferring data between different applications or different layers within a single application. You can look at them as dumb bags of information the sole purpose of which is to just get this information to a recipient.

    On the other hand, Value Object is a full member of your domain model. It conforms to the same rules as an Entity. The only difference between Value Object and Entity is that Value Object doesn’t have its own identity. It means that two Value Objects with the same property set should be considered the same whereas two Entities differ even if their properties match.

    Value Objects do contain logic and, typically, they are not used for transferring data between application boundaries. Read more here

提交回复
热议问题