Unless I misunderstand - Most of the articles I read on MVVM explains model in MVVM as the piece holding domain/business-logic, but what baffles me is that MVVM is a presentation layer pattern and presentation layer does not hold business logic in entirety. Can some please help me understand how the domain-logic in business layer maps to the model in the presentation layer, is the model in MVVM actually a DTO? I'd appreciate if some one can help explain with an example how business layer is mapped to a MVVM model in SOA (business logic sits behind a web service). Thanks.
MVVM, like MVC, is just a form of Separated Presentation in which the intent is to achieve separation of concerns between the part of the applicaton concerned with the logic and state of the UI and the part of the application concerned with the logic and state relating to the business domain. So MVVM doesn't really dictate anything about the form that the Model part takes as long as it is separated from presentation concerns.
The Model is purposely not coupled or dependent in any way on the presentational aspects of the application but beyond that there are many different ways to implement the "M" part of the triad. In particular, it doesn't have to map to a single object: it could mean interacting with a service that returns DTOs, it could mean publishing and subscribing to messages on a message bus or it could mean retrieving domain objects that represent entities in your domain, calling methods on them and then persisting them.
What's really unique about the MVVM pattern is the ViewModel's role in it since its purpose is to represent the state of the UI in a way that can be consumed by View technologies that have rich databinding capabilities. Without rich databinding support you would use a different form of Separated Presentation such as MVC or MVP, but the "M" part could still be the same because it's independent of the UI technology by definition. That is the important factor.
The Model in MVVM is not at all the DTO. DTO is the Data Transferable Object. Its more like the entity classes. It is basically used to transfer data from one layer to other layer; such as Presentation Layer to Business Layer or Business Layer to Data Access Layer.
And the Model mainly consists the Business Logic. Presentation Layer through View Model calls the Business Logic of Model as and when required.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With