เพื่อเลี่ยงปัญหาการผูกติดกันอย่างแน่นหนา (tight coupling) ระหว่างโมเดลกับ client ต่าง ๆ คุณอาจเลือกออกแบบ Mediator [Gamma et al.] (หรือที่รู้จักกันในชื่อ Double-Dispatch และ Callback ) interface ขึ้นมา เพื่อให้ Aggregate ใช้ publish สถานะภายในของมัน Clients จะเป็นฝ่าย implement interface ของ Mediator โดยส่ง object reference ของผู้ implement ไปให้ Aggregate เป็น argument ของ method จากนั้น Aggregate จะทำ double-dispatch ไปยัง Mediator ตัวนั้นเพื่อ publish สถานะที่ถูกขอออกมา โดยไม่ต้องเปิดเผย รูปร่างหรือโครงสร้างภายในของมันแม้แต่น้อย เคล็ดลับคือ อย่าไปผูก interface ของ Mediator เข้ากับข้อกำหนดของ view ในรูปแบบใดรูปแบบหนึ่ง แต่ให้มันจดจ่ออยู่กับการเรนเดอร์สถานะของ Aggregate ที่เราสนใจเท่านั้น:
public class BacklogItem ... {
...
public void provideBacklogItemInterest(
BacklogItemInterest anInterest) {
anInterest.informTenantId(this.tenantId().id());
anInterest.informProductId(this.productId().id());
anInterest.informBacklogItemId(this.backlogItemId().id());
anInterest.informStory(this.story());
anInterest.informSummary(this.summary());
anInterest.informType(this.type().toString());
...
}
public void provideTasksInterest(TasksInterest anInterest) {
Set<Task> tasks = this.allTasks();
anInterest.informTaskCount(tasks.size());
for (Task task : tasks) {
...
}
}
...
}
Interest provider ต่าง ๆ เหล่านี้อาจถูก implement ได้โดยคลาสอื่น ๆ ในทำนองเดียวกับที่ Entities (5) อธิบายถึงการมอบหมายงาน validation ให้กับ validator classes ที่แยกออกจากกันเป็นเอกเทศ
ขอให้ตระหนักไว้ว่า บางคนอาจมองว่าแนวทางนี้อยู่นอกเหนือความรับผิดชอบของ Aggregate โดยสิ้นเชิง ขณะที่คนอื่น ๆ อาจมองว่ามันเป็นการต่อยอด domain model ที่ออกแบบมาอย่างดีซึ่งเป็นเรื่องธรรมชาติโดยสมบูรณ์ และเช่นเคย trade-off ในลักษณะนี้ควรถูกนำไปหารือกันโดยสมาชิกในทีมเทคนิคของคุณ