its good practice to pass value object to entity methods (in terms of DDD)?
For example I have a method in my entity Customer:
SetAddress(Address invoiceAddress);
is it valid? Or I should pass address parameters as
SetAddress(string street, string town, string zip, string country);
and let the customer handle the creation of address object and if needs throw an exception.
Address is immutable object.
You should definitely pass an
Addressobject. It is valid in terms for DDD and it’s also good for extensibility (i.e. you can add more fields toAddressobject without changing the signature of theSetAddressmethod).Also the
Addressobject should contain validation logic for address information, which aCustomer.SetAddress(...)method can execute before setting the address: