Sharing the model
Now we have explored strict layering, but we still have multiple models. An alternative to copying models from one layer to another is to share a model between multiple layers, generally as an assembly. Visually, it looks like this:
Figure 12.9: Sharing a model between all three layers
There are pros and cons to everything, so no matter how much time this can save you at first, it will come back to haunt you and become a pain point later as the project advances and becomes more complex.
Suppose you feel that sharing a model is worth it for your application. In that case, I recommend using view models or DTOs at the presentation level to control and keep the input and output of your application loosely coupled from your model. This way of shielding your lower layers can be represented as follows:
Figure 12.10: Sharing a model between the domain and data layers
By doing that, you may save some time initially by sharing your model between...