Specification pattern: Difference between revisions

Content deleted Content added
ridiculed pattern even more with C# 6
Line 268:
<source lang="csharp">
var InvoiceCollection = Service.GetInvoices();
foreach (Invoicevar invoice in InvoiceCollection) {invoice.SendToCollectionIfNecessary();
invoice.SendToCollectionIfNecessary();
}
 
// Invoice methods:
public void SendToCollectionIfNecessary()
{
if (ShouldSendToCollection()) SendToCollection();
{
SendToCollection();
}
}
 
private bool ShouldSendToCollection() => currentInvoice.OverDue && currentInvoice.NoticeSent && !currentInvoice.InCollection;
 
{
return currentInvoice.OverDue
&& currentInvoice.NoticeSent
&& !currentInvoice.InCollection;
}
</source>This alternative uses foundation concepts of Get-Only Properties, Condition-Logic, and Functions. The key alternative here is Get-Only Properties, which are well-named to maintain the Domain-Driven language, and enable the continued use of the natural && operator, instead of the Specification Pattern's And() function. Furthermore, the creation of a well-named function SendToCollectionIfNecessary is potentially more useful and descriptive, than the previous example (which could also be contained in such a function, except not directly on the object apparently).