In DDD examples I often see the use of methods where I would probably have used a property. Why is this?
For example (from Strengthening your domain: Aggregate Construction)
public class Order
{
public bool IsLocal()
{
return Customer.Province == BillingProvince;
}
}
One argument for choosing methods instead of properties is when there would be any code that does something. If it just returns some internal field value then use property. If it has any logic inside or does any calculation use method. This makes it clearer to client of code that there is something happening when you call this method.
I think I've read in CLR via CSharp that Microsoft regrets making DateTime.Now
a property instead of method. It returns new value every time you call it. That should be method not property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With