ควรอ้างอิง Aggregates ภายนอกผ่าน Identity ที่ไม่ซ้ำกันระดับโลกเท่านั้น ไม่ใช่โดยการถือ object reference โดยตรง (หรือ "pointer") ตัวอย่างนี้แสดงให้เห็นใน รูป 10.6 .

Image

Figure 10.6 Aggregate BacklogItem ที่แสดงการอ้างอิง associations นอก boundary ด้วย identities

เราจะทำการ refactor source code ดังนี้

คลิกที่นี่เพื่อดูรูป code


public class BacklogItem extends ConcurrencySafeEntity  {
    ...
    private ProductId productId;
    ...
}


Aggregates ที่ใช้ object references แบบ inferred จึงมีขนาดเล็กโดยอัตโนมัติ เพราะว่า references จะไม่ถูก eagerly load Model สามารถทำงานได้ดีขึ้น เพราะว่า instances ต้องใช้เวลา load น้อยลง และใช้ memory น้อยลง การใช้ memory น้อยมีผลดีต่อทั้ง memory allocation overhead และ garbage collection