I'm looking for ways how to accept arguments in the domain model when you want to add items in it.
Let's take a look at this example:
public class Order {
public ICollection<OrderItem> Items { get; set; }
// Way 1
public void AddItem(OrderItem item) {
// Add
}
// Way 2
public void AddItem(decimal amount, Address address, string cardNumber) {
// Add
}
// Way 3
public void AddItem(ItemArgs args) {
// Add
}
}
As you can see there I have been using 3 ways but which one is right and why?
Is that okay to build up domain model entities from outside? Like create OrderItem from outside of the domain model and pass it through AddItem method
In the second case I'm accepting many arguments if there will be more properties then it could grow up.
and last one where I have argument class where are properties aggregated.
For example if I need same properties as I have in OrderItem should I accept that type directly ? But that case not happens everytime. So I don't want to have different approaches in my domain model. I would like to implement the one and follow that.
I would like to hear it from you how you manage such things in your domain model?
ItemArgs
can be changed independently of the method requirements). I'm not so sure that needing to update the method signature to accept more arguments if/when they are needed is a downside! That is necessary complexity. Adding indirection doesn't really make it simpler. – king-side-slide Nov 5 '20 at 17:59