Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DDD How to fetch a list of value objects

I have a domain model

  • Customer - Aggregate root - because an order can't exist without a customer
  • Order - entity
  • OrderStatus - value object

In my form I need a list of all OrderStatuses.

Should I fetch an empty customer entity(AR) from repository with an empty order entity which is containing a list of all OrderStatuses? This is awkward.

like image 852
user256034 Avatar asked Jan 26 '11 09:01

user256034


1 Answers

Well, it always depends on your problem domain, but lacking further info, I would say you probably need to break your modeling a little bit.

Even though an Order can't exist without a Customer, it will not be a child entity under the Customer AR. You need to introduce the notion of Bounded Contexts.

Customer would be the AR of one BC, while Order would be the AR of its own BC.

In that case, you would reference Customer from Order with a CustomerId property (not with an object reference) because they belong to different contexts, and as such they could even live in separate microservices, in separate databases.

You see where I'm going: it makes no sense to fetch an empty Customer, with an empty Order (or list of Orders) just to reach a list of Order Statuses.

Even if Order and Customer did belong to the same BC, OrderStatus is Reference Data, and would be better represented by an enum type (or better, with the Enumeration Pattern).

Have a look at this additional info:

Reference data as code

Entities, Value Objects, Aggregates and Roots

like image 183
Phillippe Santana Avatar answered Sep 24 '22 09:09

Phillippe Santana