Does references between entities of the same aggregate hurt the Aggregate Pattern from DDD?

Consider an application being implemented following Domain Driven Design.

In the same aggregation, there are Car and Computer entities that should have a one to many relationship between them (Car has one Computer and Computer can be embedded in many of Car). They are in the same aggregation because Computer only exists within Car, so the Car is the aggregation root. Below, some simplified pseudo code.

The application uses for persistence an orm that requires such entities to have explicit relationship configuration between them using references and back references such as Computer computer and Car[] cars.

Does the usage of these references between the classes on the same aggregation root hurt the aggregate pattern principle from domain driven design? In time, the only reason why Computer have an identifier, is because these entities will be persisted in different tables on the database.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>class Car
uuid id
string name
string color
# Here is the reference
uuid computer_id
Computer computer
</code>
<code>class Car uuid id string name string color # Here is the reference uuid computer_id Computer computer </code>
class Car
  uuid id
  string name
  string color

  # Here is the reference
  uuid computer_id   
  Computer computer 
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>class Computer
uuid id
string processor
int memory
int storage
# Here is the back reference
Car[] cars
</code>
<code>class Computer uuid id string processor int memory int storage # Here is the back reference Car[] cars </code>
class Computer
  uuid id
  string processor
  int memory
  int storage

  # Here is the back reference
  Car[] cars

1

To your question: “Does the usage of these references between the classes on the same aggregation root hurt the aggregate pattern principle from domain driven design?”. No. This is the intention of aggregate. One of the entity should be able to refer other entity in the same aggregate.

When you are doing DDD, aggregates are transactional boundary. And when you are persisting the entities in a normalized form in a database it could be hard to make aggregates as transactional boundary. To make aggregates as your transactional boundary, you would have to implement a lot of event store logic. Instead, I would prefer to use a [event store] (https://eventstore.org/), or (if using c#) use a library such as SqlStreamStore or NEventStore.

Or when none of these are feasible to me I would store the aggregate in serialized form along with aggregate version and aggregate id. With this it would relatively easy for me to build transactional boundary around an aggregate.

To answer in short, I would not choose to use a ORM and persist aggregates in normalized form because enforcing transactional boundary is difficult. For me this is the only issue and nothing else

1

In the same aggregation root, there are Car and Computer

I think this is where you are going wrong.

In your example Computer is the Aggregate Root. You can only have one ‘root’ object per aggregate.

If you think of things this way around your object graph just becomes a standard parent-child tree where you need to load all the objects in order to keep calculated properties on the parent valid.

Having a child reference its parent like you have is fine as long as you are happy to load the entire graph when you need a single car.

Otherwise it would be better to simply have the the computerId property as a cross aggregate link

6

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật