Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • I'm not fully convinced that mapping to a DTO is beneficial here. I've seen way too many projects that have empty DTO layers being mapped to other empty DTO layers for the sake of architecture and decoupling. I want to see behavior in a layer, or another really good reason for it's existence. Types used internally within the same system are safer to use in multiple layers provided the IDE's refactoring tools allow you to easily restructure and reorganize the code base. Commented Sep 26, 2024 at 4:20
  • That being said, if types are used across different systems such that refactoring tools in the IDE don't help, now the layer has a good reason to exist. The decoupling the DTO provides insulates other systems or components from changes that are not easily fixed. Commented Sep 26, 2024 at 4:25
  • @GregBurghardt: Define "layer". Architecturally, I would refer to "the persistence layer", which includes in it any persistence logic and related mapping. But I would refer to the concept of mapping in and of itself as a "layer of abstraction", which is not referring to an "architecture layer" in the same sense that "persistence layer" would be. So when you say "I want to see behavior in a layer", I agree with you if you're referring to an architectural layer, but not if you're referring to the other definition of "layer" that I mentioned. Commented Sep 26, 2024 at 4:58
  • 1
    @GregBurghardt: Maybe to put it differently I'm not advocating for an empty passthrough layer (i.e. a whole new service class) which does nothing but mapping. I'm advocating for the addition of a mapping to the existing layer (i.e. repository or similar service). Based on your feedback, I get the feeling that you may have interpreted this answer as suggesting the former. Commented Sep 26, 2024 at 5:01
  • Could I perhaps go a step further and propose that whatever structure sits atop a DAO (which we agree should exist in the vast majority of cases) must: 1. Implement an interface defined in the presentation layer, and 2. be introduced into the presentation layer via dependency injection? Commented Sep 26, 2024 at 10:51