Revisiting the model architecture
In our journey so far, our model has been straightforward. We simply used services that read local JSON files and fed Data Transfer Objects (DTOs) directly to our ViewModels. But as we introduce remote data, this simplistic model won’t suffice.
A straightforward approach would be to make an API call directly within our service and pass the resulting DTOs to our ViewModels. However, leaning on the principle of SoC, I believe services shouldn’t be making API calls. Moreover, using API-specific DTOs directly within our ViewModels is a slippery slope. It tightly couples our application with the external API, which can lead to maintenance nightmares, especially if the API changes often or isn’t under our control.
Instead, I advocate for mapping these DTOs to Plain Old CLR Objects (POCOs), or entities or domain models – whatever you prefer to name them. The core idea? Work with types we own and control.
Tip
By keeping...