Let me try again. Perhaps I have only seen limited Codelabs and limited articles, but every Codelab and article I have seen on MVVM represent the Model as just a list of properties or fields. Is that the gospel or was that just a common simplification?
The model as a class with a set of properties closely identifies with a table row definition in, say, an SQL table. However,
- SQL database calls often operate on multiple rows. In that case is the model a single row or multiple rows in a list?
- In SQL databases the tables may be explicitly linked with foreign keys. That information would seem pertinent to a model. Do models in MVVM somehow capture or represent such links? That information is particularly needed when hooking databases together.
Do these technical details belong in an MVVM Model? Since these are integral to the database or data source, I would assume they are handled in the Model, not the View Model. What do you think?
The structure and shape of a DTO will not necessarily be immediately translatable to and from a domain object. It’s important that when you say Model to describe whether you’re talking about domain objects or DTOs. DTOs will definitely need to mimic the SQL structure quite closely, like List for records, Object for columns, and object properties for FKs. On the other hand, domain objects will be whatever naturally describes the business data. It’s up to you to work out both ends of this pipeline, and the glue between them.
3 Likes
What you ask isn’t in any way related to MVVM but a general problem especially if you are using a database that isn’t an Object oriented database or mor in general it could be that you need multiple REST API calls to get the data for your Domain object.
So typically I use a manager object to create my domain objects from the DTO ojects.
Check out my two blog posts on using proxy objects as domain objects
Such a proxy object could easily reference multiple DTOs to form a more complex business object while giving you a lot of flexibility.
2 Likes