How to decide the structure of the Aggregate class by the relationship of entities ?
Hi,
I feel confused when comparing Axon-trade’s model and the definitions of the aggregate classes.
Here is the model diagram:
Here are parts the aggregate classes:
@Aggregate
public class OrderBook {
@AggregateIdentifier
private OrderBookId orderBookId;
@AggregateMember
private SortedSet<Order> buyOrders;
@AggregateMember
private SortedSet sellOrders;
// methods and constructor are omitted
}
public class Order {
@EntityId
private OrderId orderId;
private TransactionId transactionId;
private final long itemPrice;
private final long tradeCount;
private final PortfolioId portfolioId;
private long itemsRemaining;
// methods and constructor are omitted
}
You can see that:
- The diagram shows that OrderBook has relationship with Company, while the aggregate class OrderBook doesn’t hold the companyId
- The diagram shows that Order does NOT has direct relationship with Portfolio, while the aggregate class Order holds the portfolioId
Although the view/projection table fully reflect the model diagram above as well as the denormalized fields, I wonder why the aggregate class does not reflect the model at least.
I also notice that the check in the axon-trade project depends on the data in view/projection, would it be safe ? If a user sells the same stock twice quickly, the 2nd selling may be executed before the portfolio view of 1st selling get updated , then an oversold would happen. In this case, would it better make the check on Aggregate ?
Regards,
Sean