Re: How to model this behaviour on multiple aggregates?
"Javier Robledo Zarco [email protected] [domaindrivendesign]" <[email protected]> Wed, 22 Jun 2016 21:51:51 +0200
| Newsgroups | gmane.comp.programming.domain-driven-design |
|---|---|
| Message-ID | <CAOQ4Z+Gw3TD49C+Pcq+N8J9KV3Zx5FtwgwKraj8Z=zyZt8zxSg@mail.gmail.com> |
--001a113ff3b4daf5df0535e3444f
Content-Type: text/plain; charset="UTF-8"
Hi everyone,
I'm new both in the mailing list as in DDD so I'm completely sure that my
answer won't be the best but I want to know what you think about it.
As I see, using more than one aggregate for the Person and the relations
seems ok, but PersonRelation don't sound like something that a domain
expert would say. Instead, in this case I would go for Person and Marriage.
The marriage aggregate would have a reference to the ids of the two persons
involved.
For what concerns to the rule of one person being married with only another
person at the same time I would go with some domain services. I don't
believe this constraint must be enforced on Person aggregate, because it
must apply to both persons, so it seems weird to me checking from Person A
the relations of Person B to be sure that Person B is not already on a
Marriage relation. I think that a solution with policies implemented as
domain services would be better, an interface like CivilStatusPolicy with
implementations like IsMarried, IsDivorced, HasPartner. This policies could
use the Marriage, Divorce or Partnership repositories to check if a given
person matches the current policy.
Finally, using this solution would let us two points where the Marriage
aggregate could be created, you could use a factory (which enforces the
constraint of only one Marriage per Person) or you could create a Marriage
(now as a value object) from person with Marriage marriesTo(PersonId
anotherPerson) and then use a domain service to convert that Marriage to
something like a "FormalizedMarriage" that would be the real aggregate
where the domain expertes would be interested on. I don't really like too
much the second one because FormalizedMarrige sounds like something forced
to exist only to allow creating Marriages that don't enforce the rule of
only one Marriage per person. On the other hand, on the first solution you
lose the expresiveness of Marriage being created by Person aggregate...
Sorry for my bad english, I promise that I'll improve it on the next mail :D
Regards.
Javier
--001a113ff3b4daf5df0535e3444f
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|**| -->
<div dir="ltr">Hi everyone,<br><br>I'm new both in the mailing list as in DDD so I'm completely sure that my answer won't be the best but I want to know what you think about it.<br><br>As I see, using more than one aggregate for the Person and the relations seems ok, but PersonRelation don't sound like something that a domain expert would say. Instead, in this case I would go for Person and Marriage. The marriage aggregate would have a reference to the ids of the two persons involved.<br><br>For what concerns to the rule of one person being married with only another person at the same time I would go with some domain services. I don't believe this constraint must be enforced on Person aggregate, because it must apply to both persons, so it seems weird to me checking fro
m Person A the relations of Person B to be sure that Person B is not already on a Marriage relation. I think that a solution with policies implemented as domain services would be better, an interface like CivilStatusPolicy with implementations like IsMarried, IsDivorced, HasPartner. This policies could use the Marriage, Divorce or Partnership repositories to check if a given person matches the current policy.<br><br>Finally, using this solution would let us two points where the Marriage aggregate could be created, you could use a factory (which enforces the constraint of only one Marriage per Person) or you could create a Marriage (now as a value object) from person with Marriage marriesTo(PersonId anotherPerson) and then use a domain service to convert that Marriage to something like a
"FormalizedMarriage" that would be the real aggregate where the domain expertes would be interested on. I don't really like too much the second one because FormalizedMarrige sounds like something forced to exist only to allow creating Marriages that don't enforce the rule of only one Marriage per person. On the other hand, on the first solution you lose the expresiveness of Marriage being created by Person aggregate...<br><br>Sorry for my bad english, I promise that I'll improve it on the next mail :D<br>Regards.<br>Javier<br><br></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: Javier Robledo Zarco <[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=24777/stime=1466631557" 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=X3oDMTJldWUycDhpBF9TAzk3MzU5NzE0BGdycElkAzgxMTY5MjMEZ3Jwc3BJZAMxNzA1MDA3MTgxBHNlYwN2dGwEc2xrA3ZnaHAEc3RpbWUDMTQ2NjYzMTU1Nw--" 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=X3oDMTJmZjJtamhjBF9TAzk3MzU5NzE0BGdycElkAzgxMTY5MjMEZ3Jwc3BJZAMxNzA1MDA3MTgxBHNlYwN2dGwEc2xrA3ZtYnJzBHN0aW1lAzE0NjY2MzE1NTc-" style="text-decoration: none;">New Members</a></span>
<span class="ct" style="color: #ff7900;">1</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=X3oDMTJkbW05dG5lBF9TAzk3NDc2NTkwBGdycElkAzgxMTY5MjMEZ3Jwc3BJZAMxNzA1MDA3MTgxBHNlYwNmdHIEc2xrA2dmcARzdGltZQMxNDY2NjMxNTU3" 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;"> • <a href="https://info.yahoo.com/privacy/us/yahoo/groups/details.html" style="text-decoration: none;">Privacy</a> • <a href="mailto:[email protected]?subject=Unsubscribe" style="text-decoration: none;">Unsubscribe</a> • <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>
--001a113ff3b4daf5df0535e3444f--