Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In DDD, why they often make use of methods instead of properties?

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;
    }
}
like image 227
Robert Massa Avatar asked Dec 28 '22 08:12

Robert Massa


1 Answers

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.

like image 178
Piotr Perak Avatar answered Jan 05 '23 17:01

Piotr Perak