Content deleted Content added
GreenC bot (talk | contribs) |
Split alternative example into new Criticisms section, cleaned up examples with var keyword for clarity in both examples. Expanded Criticisms section with Anti-Pattern references, and follow-up commentary of the alternative example. |
||
Line 287:
<source lang="csharp">
// example of specification pattern logic chaining
var InvoiceCollection = Service.GetInvoices();
foreach (
if (SendToCollection.IsSatisfiedBy(currentInvoice)) {
currentInvoice.SendToCollection();
Line 303:
</source>
== Criticisms ==
Contrast without the Specification Pattern:▼
The Specification Pattern could be considered a software [[Anti-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 [[&&]] in [[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 Logic for SendToCollection and the OverDueSpecification implementation.
Most natural programming languages can accommodate ___domain-driven design with the core Object Oriented concepts.
<source lang="csharp">
var InvoiceCollection = Service.GetInvoices();
foreach (Invoice currentInvoice in InvoiceCollection) {
currentInvoice.SendToCollectionIfNecessary();
Line 321 ⟶ 328:
this.SendToCollection();
}
</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).
==References==
|