Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was looking for an answer to a similar question and agree with the two highest-ranked answers. Trying to clarify this for myself, I found that <strong>if</strong> Specifications, which go hand-in-hand with the Repository pattern, are implemented as first-class members of the domain model, then I can</p> <ul> <li><strong>reuse</strong> Specification definitions with different parameters,</li> <li><strong>manipulate</strong> existing Specification instances' parameters (e.g. to specialize),</li> <li><strong>combine</strong> them,</li> <li><strong>perform business logic</strong> on them without ever having to do any database access,</li> <li>and, of course, <strong>unit-test</strong> them independent of actual Repository implementations.</li> </ul> <p>I may even go so far and state that <em>unless</em> the Repository pattern is used together with the Specification pattern, it's not really "Repository," but a DAL. A contrived example in pseudo-code:</p> <pre><code>specification100 = new AccountHasMoreOrdersThan(100) specification200 = new AccountHasMoreOrdersThan(200) assert that specification200.isSpecialCaseOf(specification100) specificationAge = new AccountIsOlderThan('2000-01-01') combinedSpec = new CompositeSpecification( SpecificationOperator.And, specification200, specificationAge) for each account in Repository&lt;Account&gt;.GetAllSatisfying(combinedSpec) assert that account.Created &lt; '2000-01-01' assert that account.Orders.Count &gt; 200 </code></pre> <p>See <a href="http://martinfowler.com/apsupp/spec.pdf" rel="nofollow noreferrer">Fowler's Specification Essay</a> for details (that's what I based the above on).</p> <p>A DAL would have specialized methods like</p> <pre><code>IoCManager.InstanceFor&lt;IAccountDAO&gt;() .GetAccountsWithAtLeastOrdersAndCreatedBefore(200, '2000-01-01') </code></pre> <p>You can see how this can quickly become cumbersome, especially since you have to define each of the DAL/DAO interfaces with this approach <em>and</em> implement the DAL query method.</p> <p>In .NET, LINQ queries <em>can</em> be one way to implement specifications, but combining Specification (expressions) may not be as smooth as with a home-grown solution. Some ideas for that are described in <a href="https://stackoverflow.com/questions/457316">this SO Question</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload