Search code examples
c#domain-driven-designspecification-pattern

Is Specification Pattern Pointless?


I'm just wondering if Specification pattern is pointless, given following example:

Say you want to check if a Customer has enough balance in his/her account, you would create a specification something like:

new CustomerHasEnoughMoneyInTheirAccount().IsSatisfiedBy(customer)

However, what I'm wondering is I can achieve the same "benefits" of Specification pattern (such as only needing to change the business rules in on place) by using Property getter in the Customer class like this:

public class Customer
{

     public double Balance;

     public bool HasEnoughMoney
     {
          get { return this.Balance > 0; }
     }
}

From client code:

customer.HasEnoughMoney

So my question really is; what is the difference between using the property getter to wrap the business logic, and creating Specification class?

Thank you all in advance!


Solution

  • Because with the specification class you can create new criterias without modification of the objects themselves.