What is the difference between an MVC Model object, a domain object and a DTO

前端 未结 6 1494
遇见更好的自我
遇见更好的自我 2020-12-22 15:54

What is the difference between a MVC Model object, a domain object and a DTO?

My understanding is:

MVC Model object:

Models the data

6条回答
  •  悲&欢浪女
    2020-12-22 16:28

    My understing (in a big short) is as follows:

    (MVC) Model object:

    • represent some things in a some usage context eg. PersonEditModel, PersonViewModel or just PersonModel
    • has no business logic
    • can be subject of some valdation logic etc.
    • used to provide data from one application layer to another eg. MVC Controller <-> MVC View

    Domain object:

    • represents some business object (real world object in the problem domain)
    • has business logic
    • do not allow invalid object state, has methods to properly change object's state
    • used to encapsulate business logic related to it
    • have not to be used to persist data (or even should not)

    DTO (Data Transfer Object):

    • similar to Model object but should have flat structure
    • only simple type properties/fields (strings, numbers, datetimes, booleans)
    • used to transfer data cross application boundaries eg. between web server and web browser

提交回复
热议问题