language agnostic - DDD: Aggregates and sub-aggregates -


i have quite complex aggregate, aggregate root order. contains entities (eg. orderitem) meaningless outside aggregate. there entities supposed part of aggregate, make sense outside aggregate (eg. shippingmethod or invoice).

is right have repository complex aggregate (loading whole aggregate root's id) , have crud repository managing possible shipping methods , repository listing invoices?

more generally, possible in ddd have aggregate, part of aggregate?

you can consider "an aggregate, part of aggregate" "an aggregate holds aggregate's reference".

for example

public class order {     private invoice invoice; }  <class name="order" table="t_order">     <one-to-one name="invoice" column="invoice_id" /> </class> 

if both order , invoice aggregates in context, i'll have orderrepository , invoicerepository.you can retrieve order using

orderrepository.findby(orderid) 

and can retrieve invoice using

invoicerepository.findby(invoiceid)  

or

order order = orderrepository.findby(orderid); invoice invoice = order.getinvoice(); 

and there famous article how design aggregates(http://dddcommunity.org/library/vernon_2011/) suggests realizing relationships using identity reference.

public class order {     private invoiceid invoiceid; }  <class name="order" table="t_order">     <component name="invoiceid">         <property name="value" column="invoice_id" />     </component> </class> 

you can retrieve order using

orderrepository.findby(orderid) 

and can retrieve invoice using

invoicerepository.findby(invoiceid)  

or

order order = orderrepository.findby(orderid); invoice invoice = invoicerepository.findby(order.getinvoiceid());  

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -