mardi 5 janvier 2021

Specification Pattern vs (Fluent) Validation

What is different between Specification Pattern and (Fluent) Validation? Are they similar?

// Specification
public class PremiumSpecification<T> : CompositeSpecification<T>
{
    private int cost;
    public PremiumSpecification(int cost) {
        this.cost = cost;
    }
 
    public override bool IsSatisfiedBy(T o) {
        return (o as Mobile).Cost >= this.cost; // HERE
    }
}
// Fluent Validation
public class CustomerValidator : AbstractValidator<Customer> {
  public CustomerValidator() {
    RuleFor(customer => customer.Cost).GreaterThanOrEqualTo(0);
  }
}

Aucun commentaire:

Enregistrer un commentaire