I am reading the documentation of Microsfot acording with DDD. And in the validations sections it use this example to exaplain that the final state of an address it would be invalid:
public void SetAddress(string line1, string line2,
string city, string state, int zip)
{
_shippingAddress.line1 = line1 ?? throw new ...
_shippingAddress.line2 = line2;
_shippingAddress.city = city ?? throw new ...
_shippingAddress.state = (IsValid(state) ? state : throw new …);
}
And it tells: If the value of the state is invalid, the first address line and the city have already been changed. That might make the address invalid.
But I don't understand 2 points:
1.- If the state is invalid, wouldn't it throw an exception and then the address is not created?
2.- The first line of the address, if I don't misunderstand, the unique constrainst is that it has to be not null, but accept any value. If it is null, it throws an exception and the address is not created. if it is not null, it is correct, why if the state is not valid, the first line of the address is not valid?
Thanks.