0

I have a domain called product_catalog. In my domain a Brand can owns many products. (1 to Many relationship) A category could have many products, and a product could belong to many categories. It's a N-to-M relationship.

If I design product as the aggregate root, it will make no sense to retrieve product to create a brand. Besides that, I need to retrieve all brands and make it possible for the user create more brands So I suspect that Brand is an aggregate root too. Is that right?

What about categories and product?

p.magalhaes
  • 7,595
  • 10
  • 53
  • 108

1 Answers1

3

An entity child in an aggregate doesn't have its own lifecycle, i.e., an entity object cannot exist on its own outside the aggregate, but depends on an object of the root entity. The child entity has a local unique identity inside the aggregate, while the root entity has a global unique identity.

To know whether an entity is a child of an aggregate root entity, ask to yourself: Can the entity exists without the root entity? If it can exists on its own, then it isn't a child, it is the root of another aggregate, and you should reference it by the id.

So I suspect that Brand is an aggregate root too. Is that right?

Yes, a Brand exists on its own, without a Product.

What about categories and product?

Well, I think they belong to different aggregates, since I see categories as a way of classifying the products, but the product exists on its own. Besides that, the product could belong to many categories. So Product is not a child of Category. And the opposite neither.

Category and Brand are two aggregates.

I doubt about Product. It could be an entity child of Brand. It depends on your business rules. Is a product owned by a Brand independent? Can it exists on its own? Or it doesn't make sense that the product exists without its Brand?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
choquero70
  • 4,470
  • 2
  • 28
  • 48
  • Good explanation, I feel Product is an entity and Brand is a different entity... Category is just an attribute of Product. – Hooman Bahreini Feb 25 '19 at 00:55
  • @HoomanBahreini Yes, Product and Brand are both entities,what I was wondering was if they both belong to the same aggregate (Brand would be the entity root,and Product an entity child),or Product is the entity root of another aggregate. Regarding Category, if by "just an attribute" you mean it is a value object,I don't think so, I think from the question that a Category has identity, so it would be an entity (the root of another aggregate).A product can belong to many categories, Product entity would have a list of the ids of the categories it belongs to (an aggregate is referenced by its id). – choquero70 Feb 25 '19 at 03:32