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

前端 未结 6 1480
遇见更好的自我
遇见更好的自我 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:17

    Any definition for most of the objects is various based on place of using of objects:

    Model: is a general definition for using object in client or server.

    1. Model View : is a object using in client most of the time.
    2. Domain Object : is a object using in server and transfering data to the database.
    3. Data Transfer Object(DTO) : is a object that transfer data from one object to another object, specially in getting data in API Call(for example: in api GET Method call for getting data you must not to give database models to client, for this purpose you use dto).

    Notice: the definitions are true most of the time but in some situations arent't practical.

    0 讨论(0)
  • 2020-12-22 16:18

    Domain and model objects are essentially the same, and may contain business logic. Depending on implementation, domain and DTO objects may be equivalent if you remove business logic from the model into a service class.

    Often a key variant of the DTO is the View Model, which is used purely to transfer data between the domain model and the view, although often a View Model may contain logic, although this should be purely UI logic.

    0 讨论(0)
  • 2020-12-22 16:21

    The Domain and DTO can also be your "model" objects - you can have a view to render the details of the "Customer" domain object.

    A domain object can have business logic to enforce the properties of the domain entity. validation is one such case. The domain object by itself does not contain persistence related methods, but it can have meta-data (like annotations) to support persistence

    the POJO programming model makes it possible to use the same object as your domain, DTO and model objects - essentially, you will not be implemented any extraneous interfaces that will only apply to one layer but does not apply to others.

    0 讨论(0)
  • 2020-12-22 16:22
    A DTO = is an object that carries data between processes.
    

    But the most interesting part is that, it does not have any behavior except for storage and retrieval of its own data!!!

    Sticking with the MVC methodology...

    Domain = subject of your entire application.
    
    Model = contains the (programming languages objects : EX: C# objects) to make up the universe of your application.
    

    They can obvioussly have behaviour and properties(see difference with DTO).

    Often an application (a light one) can have one model - case in which your model is exactly your domain. Another model can be, a totaly different object type, that is processing another one. Both of them, in this case are part of your domain, and are named "domain models - objects".

    Hopefully this answer is exhaustive and makes it all clear for you !

    0 讨论(0)
  • 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
    0 讨论(0)
  • 2020-12-22 16:30

    1) No, It is a definition of ViewModel. MVC Model Object and Domain Object both are same.
    2) Domain Models (Objects) are always present, business logic is optional
    3) If there is no business logic in Domain Object then automatically it becomes DTO.

    0 讨论(0)
提交回复
热议问题