Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The first question is the most difficult to answer. Is it bad practice to have Entities depend on outside classes? It's certainly not the most common thing to do.</p> <p>If, for example, you inject a Repository into your Entities you effectively have an implementation of the <a href="https://en.wikipedia.org/wiki/Active_record_pattern" rel="nofollow noreferrer">Active Record pattern</a>. Some people like this pattern for the convenience it provides, while others (like me) consider it a code smell or anti-pattern because it violates the <a href="https://en.wikipedia.org/wiki/Single_responsibility_principle" rel="nofollow noreferrer">Single Responsibility Principle</a> (SRP).</p> <p>You could argue that injecting other dependencies into Entities would pull you in the same direction (away from SRP). On the other hand you are certainly correct that if you don't do this, the pull is towards an <a href="https://martinfowler.com/bliki/AnemicDomainModel.html" rel="nofollow noreferrer">Anemic Domain Model</a>.</p> <p>I struggled with all of this for a long time until I came across Greg Young's (abandonded) <a href="https://cqrs.files.wordpress.com/2010/11/cqrs_documents.pdf" rel="nofollow noreferrer">paper on DDDD</a> where he explains why <strong>the stereotypical n-tier/n-layer architecture will always be CRUDy</strong> (and thus rather anemic).</p> <p>Moving our focus to modeling Domain objects as <strong>Commands and Events</strong> instead of Nouns seems to enable us to build a proper object-oriented domain model.</p> <p>The second question is easier to answer. You can always use an <a href="https://stackoverflow.com/questions/1926826/cant-combine-factory-di/1927167#1927167">Abstract Factory to create instances at run-time</a>. With Castle Windsor you can even use the Typed Factory Facility, relieving you of the burden of implementing the factories manually.</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. 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