In the BC that contains Order
it might indeed be the case that Product
, as part of an OrderLine
, is a value object, consisting of values such as ProductId
, Name
etc.
The order context does not need to know about product entities, since order lines usually only contain simple value-only properties (productId/SKU, a name, quantity and price-per/item). Therefore, Order
could provide a function such as
void addOrderLine(ProductId productId, String productName, BigDecimal pricePerItem, int quantity).
It's actually not relevant for the "Order"-BC where these values for productId
, productName
etc originate from.
In practice, however, it's probably very likely that these values can be obtained from another bounded context, say the "Product"-BC, which is responsible for inventory management etc.
It's quite common to let the UI orchestrate these BCs:
- The UI (a web shop for customers, for example) loads the products and their prices from the "Product-BC"
- The user places products into a shopping basket (let's assume for simplicity that this is also the "Order-BC"). For, the UI fires commands such as
AddToShoppingBasketCommand(productId, productName, quantity, price)
which are handled by the "Order"-BC.
- When the user wants to place the order for the current shopping basked, it fires a
PlaceOrderCommand
.
- The command handler for
PlaceOrderCommand
takes the current shopping basket and constructs a corresponding Order
; all it needs are, for each product, the respective properties of products that were already listed in the shopping basket (and were originally in the AddToShoppingBasketCommand
). Note that it does not need to know about the notion of a Product
entity from the Product-BC.