Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The google testing blog has <a href="http://googletesting.blogspot.com/2008/10/to-new-or-not-to-new.html" rel="nofollow noreferrer">a post which tries to answer this question</a>. The basic idea is that you can classify each of your classes as a "newable" or "injectable", and that it is OK to just "new up" the newables.</p> <p>I distinguish 2 main categories of "newables":</p> <ul> <li>values like <code>int</code>, <code>string</code>, <code>DateTime</code>, etcetera.</li> <li>entities like <code>Customer</code>, <code>Order</code>, <code>Employee</code>, etcetera. I think your <code>UserCredentials</code> class falls under this heading.</li> </ul> <p>It's important to realize that <strong>newables can have (testable) behavior</strong>. If you make the mistake of thinking that newables shouldn't have any behavior or unit tests, you'll end up with the <a href="http://martinfowler.com/bliki/AnemicDomainModel.html" rel="nofollow noreferrer">anemic domain model</a> anti-pattern.</p> <p>A side-effect of having "newables" with behavior is that this behavior can't be abstracted away in the unit tests of your injectables. This is OK; it is normal to have some strong coupling between your domain model and the rest of your application.</p> <p>Also, newables are allowed to know about injectables, but they only cooperate with them transiently. For example, <code>UserCredentials</code> should not take a <code>IUserDatabase</code> as a constructor argument. Instead, there might be a <code>UserCredentials.Verify(IUserDatabase)</code> method.</p> <p><strong>edit:</strong> I'm currently not so sure anymore about what I wrote above. Entities can also be constructed via (injectable) factories instead of calling their constructor directly. The factory implementation can then inject things in the entity.</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.
 

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