Content deleted Content added
Add external link |
m change source to syntaxhighlight |
||
Line 9:
=== [[C Sharp (programming language)|C#]] ===
<
public interface ISpecification
{
Line 133:
}
</syntaxhighlight>
=== [[C Sharp (programming language)|C# 6.0]] with generics ===
<
public interface ISpecification<T>
{
Line 225:
public override bool IsSatisfiedBy(T candidate) => !other.IsSatisfiedBy(candidate);
}
</syntaxhighlight>
=== [[Python (programming language)|Python]] ===
<
from abc import abstractmethod
from dataclasses import dataclass
Line 270:
return not self.subject.is_satisfied_by(candidate)
</syntaxhighlight>
==Example of use==
Line 286:
Using these three specifications, we created a new specification called SendToCollection which will be satisfied when an invoice is overdue, when notices have been sent to the customer, and are not already with the collection agency.
<
var OverDue = new OverDueSpecification();
var NoticeSent = new NoticeSentSpecification();
Line 301:
}
}
</syntaxhighlight>
== Criticisms ==
Line 312:
Alternative example, without the Specification Pattern:
<
var InvoiceCollection = Service.GetInvoices();
foreach (var invoice in InvoiceCollection) invoice.SendToCollectionIfNecessary();
Line 324:
private bool ShouldSendToCollection() => currentInvoice.OverDue && currentInvoice.NoticeSent && !currentInvoice.InCollection;
</syntaxhighlight>
==References==
|