Thoughts and questions about data mapping and DDD in general

"[email protected] [domaindrivendesign]" <[email protected]> 27 Apr 2017 16:44:24 +0000
Newsgroups gmane.comp.programming.domain-driven-design
Message-ID <[email protected]>
--9nlWnTS9ocNmxdhsK3FKVLWiM6a5jwOaA8HvrLV
Content-Transfer-Encoding: base64
Content-Type: text/plain; charset="UTF-8"

SGV5IGd1eXMsIA0KIA0KDQogSG93IGRvIHlvdSBtYW5hZ2UgZGF0YSBtYXBwaW5nIGluIERERD8N
CiBUbyBtZSwgdG8gZm9sbG93IERERCBwcmluY2lwbGVzLCB3ZSdkIG5lZWQgdG8gZG8gdGhlIGZv
bGxvd2luZzoNCiBjbGllbnRzIGhhdmUgdGhlaXIgb3duIERUTywgdG8gcmVwcmVzZW50IHRoZSBk
YXRhIGluIHRoZWlyIGxldmVsIGNsaWVudHMgZG8gTk9UIHdvcmsgd2l0aCBkb21haW4gb2JqZWN0
cyBzdWNoIGVudGl0aWVzLCBhZ2dyZWdhdGVzIC4uLiBkb21haW4gbW9kZWwsIGluIGdlbmVyYWw7
IGNsaWVudHMgY2FsbCwgdmlhIGNvbnRyb2xsZXJzL2FwcGxpY2F0aW9uIHNlcnZpY2VzLCB0aGUg
ZG9tYWluIHNlcnZpY2VzIGZyb20gdGhlIGRvbWFpbiBkb21haW4gc2VydmljZXMgdGFsayB0byBy
ZXBvc2l0b3JpZXMsIGFuZCBib3RoIHdvcmsgd2l0aCB0aGUgZG9tYWluIG1vZGVsIHJlcG9zaXRv
cnkgZGVmaW5pdGlvbiBiZWxvbmdzIHRvIHRoZSBkb21haW4gbGF5ZXIsIGJ1dCBpbXBsZW1lbnRh
dGlvbiBiZWxvbmdzIHRvIGluZnJhc3RydWN0dXJlOyByZXBvc2l0b3J5IGltcGxlbWVudGF0aW9u
IG5lZWQgbWFwcGVycyB0byBjb252ZXJ0IGZyb20gZG9tYWluIG1vZGVsIHRvIERUTyBhbmQgdmlj
ZS12ZXJzYTsgU29tZSBjb25zZXF1ZW5jZXMgb2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ZW50dWFsbHksIGNvbnZlcnRzIGRhdGEgYmFjayB0byBkb21haW4gb2JqZWN0cyB0
byByZXR1cm4gdG8gdGhlIGNhbGxlcik7IFRoYXQncyB0aGUgb25seSB3YXkgSSBjYW4gdGhpbmsg
b2YsIHByZXNlcnZpbmcgdGhlIERERCBwcmluY2lwbGVzLiANCiBEb2luZyBzbywgd2Uga2luZGEg
cHJlc2VydmUgZG9tYWluIHRhbGtpbmcgYWJvdXQgZG9tYWluLCBpbmZyYSB0YWxraW5nIGFib3V0
IGRhdGEsIG5vICdpbmZyYS1yZWxhdGVkJyBjb25maWd1cmF0aW9uIG9uIGRvbWFpbiBvYmplY3Rz
LCBhbmQgYWxzbyBubyBjbGllbnRzIHNwZWFraW5nIGluIHRoZSBkb21haW4gdGVybXMuIA0KIA0K
DQogV2hhdCBkbyB5b3UgdGhpbms/IEhvdyBkbyB5b3UgcGxheSB3aXRoIGRhdGEgbWFwcGluZz8g
DQogQnkgdGhlIHdheSwgZG8geW91IGFncmVlIHdpdGggbXkgd29yZHM/DQogDQoNCiBDaGVlcnMs
IA0KIFBlZHJvDQoNCg==


--9nlWnTS9ocNmxdhsK3FKVLWiM6a5jwOaA8HvrLV
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit





<head>

<style type="text/css">
<!--

/* start of attachment style */
       .ygrp-photo-title{
         clear: both;
         font-size: smaller;
         height: 15px;
         overflow: hidden;
         text-align: center;
         width: 75px;
       }
       div.ygrp-photo{
         background-position: center;
         background-repeat: no-repeat;
         background-color: white;
         border: 1px solid black;
         height: 62px;
         width: 62px;
       }

       div.photo-title 
         a,
         div.photo-title a:active,
         div.photo-title a:hover,
         div.photo-title a:visited {
           text-decoration: none; 
       }

       div.attach-table div.attach-row {
         clear: both;
       }

       div.attach-table div.attach-row div {
         float: left;
         /* margin: 2px;*/
       }

       p {
         clear: both;
         padding: 15px 0 3px 0;
	 overflow: hidden;
       }

       div.ygrp-file {
         width: 30px;
         valign: middle;
       }
       div.attach-table div.attach-row div div a {
         text-decoration: none;
       }

       div.attach-table div.attach-row div div span {
         font-weight: normal;
       }

       div.ygrp-file-title {
         font-weight: bold;
       }
 /* end of attachment style */
        -->
        </style>
        </head>
<html>
<head>
<style type="text/css">
<!--
#ygrp-mkp {
  border: 1px solid #d8d8d8;
  font-family: Arial;
  margin: 10px 0;
  padding: 0 10px;
}

#ygrp-mkp hr {
  border: 1px solid #d8d8d8;
}

#ygrp-mkp #hd {
  color: #628c2a;
  font-size: 85%;
  font-weight: 700;
  line-height: 122%;
  margin: 10px 0;
}

#ygrp-mkp #ads {
  margin-bottom: 10px;
}

#ygrp-mkp .ad {
  padding: 0 0;
}

#ygrp-mkp .ad p {
  margin: 0;
}

#ygrp-mkp .ad a {
  color: #0000ff;
  text-decoration: none;
}
-->
</style>
</head>
<body>



<!-- |**|begin egp html banner|**| -->

<br><br>

<!-- |**|end egp html banner|**| -->


<p><span>Hey guys,&nbsp;</span></p><p><span><br></span></p><p><span>How do you manage data mapping in DDD?</span></p><p>To me, to follow DDD principles, we&#39;d need to do the following:</p><p><ul class=""><li>clients have their own DTO, to represent the data in their level</li><li>clients do NOT work with domain objects such entities, aggregates ... domain model, in general;</li><li>clients call, via controllers/application services, the domain services from the domain</li><li>domain services talk to repositories, and both work with the domain model</li><li>repository definition belongs to the domain layer, but implementation belongs to infrastructure;</li><li>repository implementation need mappers to convert from domain model to DTO and vice-versa;</li></ul><div>Some consequences of the
  DDD are that, in the domain model, I&#39;d never put JPA annotations (and any other infrastructure-related stuff). DTOs, in the infrastructure layer, would be the classes that are actually mapped with such a thing.&nbsp;</div><div><br></div><div>But then we need data mapping between client and domain and also domain and infrastructure.&nbsp;</div><div>Where do you usually put it? Would it be kind of separate modules such as:</div><div><ul><li>a module (separate library) that maps client DTO&#39;s to domain objects, and the model depends on it;</li><li>a module (separate library) that maps domain objects to infrastructure (example: DB) model and vice-versa, and the infrastructure depends on it (repository implementation receives domain objects as parameters, convert them or build whateve
 r query it needs, persist/fetch data and, eventually, converts data back to domain objects to return to the caller);</li></ul><div>That&#39;s the only way I can think of, preserving the DDD principles.&nbsp;</div><div>Doing so, we kinda preserve domain talking about domain, infra talking about data, no &#39;infra-related&#39; configuration on domain objects, and also no clients speaking in the domain terms.&nbsp;</div><div><br></div><div>What do you think? How do you play with data mapping?&nbsp;</div><div>By the way, do you agree with my words?</div><div><br></div><div>Cheers,&nbsp;</div><div>Pedro</div></div>



<!-- |**|begin egp html banner|**| -->

<br>


<br>

<!-- |**|end egp html banner|**| -->


<div width="1" style="color: white; clear: both;"/>__._,_.___</div>

      
  

    
    <div id="fromDMARC" style="clear:both; margin-top: 10px;">
         <hr style="height:2px ; border-width:0; color:#E3E3E3; background-color:#E3E3E3;">
         Posted by: [email protected]         <hr style="height:2px ; border-width:0; color:#E3E3E3; background-color:#E3E3E3;">
    </div>
<!-- Start Recommendations -->
<!-- End Recommendations -->



<!-- |**|begin egp html banner|**| -->

  <img src="http://geo.yahoo.com/serv?s=97476590/grpId=8116923/grpspId=1705007181/msgId=24818/stime=1493327931" width="1" height="1"> <br>

<!-- |**|end egp html banner|**| -->

  
<!-- |**|begin egp html banner|**| -->

<br>



   
     
 
        <!-- |**|begin egp html banner|**| -->
        <div id="ygrp-vital" style="background-color: #f2f2f2; font-family: Verdana; font-size: 10px; margin-bottom: 10px; padding: 10px;">

        <span id="vithd" style="font-weight: bold; color: #333; text-transform: uppercase; "><a href="https://groups.yahoo.com/neo/groups/domaindrivendesign/info;_ylc=X3oDMTJlZ3E0a2M5BF9TAzk3MzU5NzE0BGdycElkAzgxMTY5MjMEZ3Jwc3BJZAMxNzA1MDA3MTgxBHNlYwN2dGwEc2xrA3ZnaHAEc3RpbWUDMTQ5MzMyNzkzMQ--" style="text-decoration: none;">Visit Your Group</a></span>

     <ul style="list-style-type: none; margin: 0; padding: 0; display: inline;">
            <li style="border-right: 1px solid #000; font-weight: 700; display: inline; padding: 0 5px; margin-left: 0;">
      <span class="cat"><a href="https://groups.yahoo.com/neo/groups/domaindrivendesign/members/all;_ylc=X3oDMTJmcjE1ZW9qBF9TAzk3MzU5NzE0BGdycElkAzgxMTY5MjMEZ3Jwc3BJZAMxNzA1MDA3MTgxBHNlYwN2dGwEc2xrA3ZtYnJzBHN0aW1lAzE0OTMzMjc5MzE-" style="text-decoration: none;">New Members</a></span>
      <span class="ct" style="color: #ff7900;">2</span>
    </li>
                                              </ul>
  </div>


<div id="ft" style="font-family: Arial; font-size: 11px; margin-top: 5px; padding: 0 2px 0 0; clear: both;">
  <a href="https://groups.yahoo.com/neo;_ylc=X3oDMTJkdnN2dTN0BF9TAzk3NDc2NTkwBGdycElkAzgxMTY5MjMEZ3Jwc3BJZAMxNzA1MDA3MTgxBHNlYwNmdHIEc2xrA2dmcARzdGltZQMxNDkzMzI3OTMx" style="float: left;"><img src="http://l.yimg.com/ru/static/images/yg/img/email/new_logo/logo-groups-137x15.png" height="15" width="137" alt="Yahoo! Groups" style="border: 0;"/></a>
  <div style="color: #747575; float: right;"> &bull; <a href="https://info.yahoo.com/privacy/us/yahoo/groups/details.html" style="text-decoration: none;">Privacy</a> &bull; <a href="mailto:[email protected]?subject=Unsubscribe" style="text-decoration: none;">Unsubscribe</a> &bull; <a href="https://info.yahoo.com/legal/us/yahoo/utos/terms/" style="text-decoration: none;">Terms of Use</a> </div>
</div>

<!-- |**|end egp html banner|**| -->

  </div> <!-- ygrp-msg -->

   


  <br>

<!-- |**|end egp html banner|**| -->


<div style="color: white; clear: both;"/>__,_._,___</div>
</body>

</html>

--9nlWnTS9ocNmxdhsK3FKVLWiM6a5jwOaA8HvrLV--