Specification pattern: Difference between revisions

Content deleted Content added
m Criticisms: bad link repair, replaced: C#C# using AWB
Line 258:
 
== Criticisms ==
The Specification Pattern could be considered a software [[Antianti-pattern|Anti-Pattern]]:
* [[Cargo cult programming|Cargo Cult Programming]] - There lacks a well-defined purpose for this pattern, and there's no guide when to implement it or not. Also, see [[Law of the instrument]].
* [[Inner-platform effect]] - And() function which directly replicate [[Short-circuiting operator|&&]] in [[C Sharp (programming language)|C#]]. Also, Not() and potentially more. Also, see [[Reinventing the wheel|Reinventing the square wheel]].
* [[Spaghetti code#Lasagna code|Spaghetti/Lasagna Code]] - Separate classes for each part of the specification fragments what could be a cohesive object. In the example above, OverDue is an extra layer between the Logiclogic for <code>SendToCollection</code> and the <code>OverDueSpecification</code> implementation.
Most natural programming languages can accommodate ___domain-driven design with the core Object Orientedobject-oriented concepts.
 
Alternative example, without the Specification Pattern:
Line 278:
private bool ShouldSendToCollection() => currentInvoice.OverDue && currentInvoice.NoticeSent && !currentInvoice.InCollection;
 
</source>This alternative uses foundation concepts of Getget-Onlyonly Propertiesproperties, Condition-Logiccondition logic, and Functionsfunctions. The key alternative here is Get-Only Properties, which are well-named to maintain the Domain___domain-Drivendriven language, and enable the continued use of the natural <code>&&</code> operator, instead of the Specification Pattern's <code>And()</code> function. Furthermore, the creation of a well-named function <code>SendToCollectionIfNecessary</code> 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).
 
==References==