1

I utilize DDD in my project.

ProductCat[Id , Name]
Product[Id, ProductCatId, name]
ProductImages[Id,ProductId,url]
  1. My Relationship between Product and ProductImages is correct OR ProductImages is Value Object so must implement in this ProductImages[ProductId, url]
  2. What's aggregate root among ProductCat, Product, ProductImages?

I know all reference from external of an aggregation to this must be from aggregate root and think ProductCat is aggregate root because it's in a higher level in the hierarchy.

MattDavey
  • 8,897
  • 3
  • 31
  • 54
Mohammadreza
  • 3,139
  • 8
  • 35
  • 56

2 Answers2

2

It somewhat depends on your Bounded Context and what you are going to do with your ProductImages.

If a ProductImage will always only occur within the context of a Product as in, e.g., a simple shopping site, then it could be part of the Product AR. If you regard a ProductImage as a true property of a Product in your BC, it could even be a ValueObject, as two equal images (as in "same pixels") of a product are probably regarded interchangeable. W/o knowing your BC requirements, it seems reasonable to make ProductImage an entity within Product (see @Meta-Knight's answer), which lets you talk about the specific images of your product (say "main image", "alternate image 1", "alternate image 2", ...).

If you are going to use the ProductImages on their own setting, say, e.g., on a page that displays the latest ProductImages some user submitted to your site, they should be their own AggregateRoot. So first try to model your domain, and then identify your ARs.

Alexander Langer
  • 2,883
  • 16
  • 18
  • +1 for mentioning different bounded contexts. It's always astounding how many people claim to be "utilizing DDD" when they have given zero thought to the contexts. – MattDavey Nov 29 '13 at 09:21
0

I see two aggregate roots: ProductCat and Product. And ProductImages would be part of the Product aggregate, because it is specific to a product.

Your ProductImages doesn't necessarily need an ID, because it's not an Aggregate root. And the ID can be unique only inside the aggregate. It also doesn't necessarily need a reference to the ProductId, because it's already part of a product.

Meta-Knight
  • 17,626
  • 1
  • 48
  • 58