Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between Model, ViewModel and DTO? [closed]

I am an ASP.NET MVC developer and I am confused. What's the difference between Model, ViewModel and DTO (Data Transfer Object)? Is it ok for model to have methods that will save itself to database?

like image 848
Art Drozdov Avatar asked Dec 08 '22 11:12

Art Drozdov


1 Answers

DTO is an object for passing data in case of communication between layers. It's a general pattern that is not tied to ASP.NET MVC.

ViewModel contains a data specific to particular view, is passed to that view in controller and is used in the view for rendering. It's a pattern specific to ASP.NET MVC (don't mix up with ViewModel from MVVM - they are different)

Model is a set of objects that represent your business domain. It can contain methods that will save it to DB depending of what pattern you will choose to build it (something like Active Record in your case).

like image 152
Oleksandr Kobylianskyi Avatar answered Mar 18 '23 10:03

Oleksandr Kobylianskyi