Created
January 27, 2011 05:57
-
-
Save liammclennan/798133 to your computer and use it in GitHub Desktop.
tell-don't-ask vs. no external dependencies on domain objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// tell don't ask means I might do something like this | |
var folder = new Folder("foo"); | |
folder.Delete(); | |
// but for that to work the folder class needs to depend on a file IO service (to do the deleting). | |
// the alternative is procedural | |
public class FolderService | |
{ | |
public FolderService(IFileSystem fileSystem) {...} | |
public void Bar() | |
{ | |
var folder = new Folder("foo"); | |
fileSystem.Delete(folder.Path); // here is the tell-dont-ask violation | |
} | |
} | |
// what is the right way to do this? |
Thanks everyone. Udi talks about Domain Events at http://www.udidahan.com/2009/06/14/domain-events-salvation/. Domain Events appear to be an elegant partial solution to the original problem. I say partial because an external dependency is still required.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FWIW, I've build a number of large systems using Event Sourcing - I'm giving a talk next week as it happens - and I would never go back to using anything else. Testing is a breeze.