-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Remove AddOrderItem method from Order class #1416
base: dev
Are you sure you want to change the base?
Remove AddOrderItem method from Order class #1416
Conversation
@AndriiTokarskyi AndriiTokarskyi I have a quick question. I think we should interact with entities in a aggregate via Aggregateroot. In this case since Order is Aggregate, So I think it makes sense to have AddOrderItem in Order class. What are your thoughts? |
Yes, I believe that's the point of DDD pattern showcase within Ordering service with complex domain entities encapsulating business knowledge, validation, and other domain-related responsibilities within its aggregate root.
Within this PR as I see, the primary driver is the ability to propagate orders to ctor and allow it to add items on its own. However, I would still argue it's a poorer practice as we might want to return some validation results, etc success, errors whatever objects for each individual order item to asses it within our orchestration logic. For resolving bulk orders I would much rather opt into implementing AddOrderItems instead of cramming these 'possibly expanded in future' essentials into ctor. One more thing is that some items within this PR go out of the scope of the proposed change. (Some method renames etc) |
{ | ||
order.AddOrderItem(item.ProductId, item.ProductName, item.UnitPrice, item.Discount, item.PictureUrl, item.Units); | ||
} | ||
var order = new Order( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you wish to handle bulk complexity I would rather opt into implementing AddOrderItems
instead of CTOR where you lose some flexibility like returning results, async, etc..
Reasons being AddOrderItem can/could change from void
to some functional object, validation, error result with some success flag for instance since it should encapsulate some logic which currently is not there but this is still a showcase of the pattern.
@@ -43,7 +43,7 @@ public OrderItem(int productId, string productName, decimal unitPrice, decimal d | |||
|
|||
public string GetPictureUri() => _pictureUrl; | |||
|
|||
public decimal GetCurrentDiscount() | |||
public decimal GetDiscount() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename is out of proposed scope of this PR
Remove AddOrderItem from Order's public interface since it is not its behaviour.