DDD: Where is it most appropriate to get a list of value objects
Asked Answered
S

1

5

I've got a value type called "Product Type" that is assigned to a product. (A product has one product type)

To allow the user to select the type from a list, I'm going to fill a dropdown. Where is it most appropriate to retrieve the list of product types? A class implementing a repository pattern?

Edit: Clarified by changing product code to product type. A product type is something like "DVD"/"CD"/"Blu Ray"/etc.

Sanbo answered 23/5, 2009 at 12:38 Comment(7)
Do you want to create a list of product codes for all existing products?Mercurialism
@Daniel Not necessarily. There may be no existing products. I'm just interested in the pattern I should be using to grab the list of product codes (value objects) from the database.Sanbo
The repository pattern seems a resonable choice for that. Are you thinking about it because of entity vs. value?Mercurialism
@Daniel Indeed. It seems odd to have a repository for a value type. Plus, I have read that repositories should return entities only.Sanbo
I would not consider the product type a value type. Think of the departments of a company - even if you just use the department name to cluster employees, it is quite obviouse that it usualy should be a first class entity. Maybe it will be extended. Maybe not. But I would really consider a product type not less an entity than a department.Mercurialism
@Daniel Lets just say for the purpose of this discussion that in my domain product type is a value object in the context of DDD.Sanbo
In this case I would handle it just like an enum - in C# it is a static method of the type like MyEnum.GetValues(). It's just a value type - no need to add extra classes and stuff.Mercurialism
P
6

Product seems to be aggregate root, so list of product types should be in ProductRepository.

Phonetic answered 23/5, 2009 at 13:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.