I have this class, which creates a document and saves it:
public class DocCreator
{
private IDocumentStore _documentStore;
public DocCreator(IDocumentStore documentStore)
{
_documentStore = documentStore;
}
public void CreateAndSave()
{
var doc = new Document();
doc.Title = "this is a title";
doc.Content = whateverStream;
doc.Hash = CalculateHash(doc.Content);
//[do more things to create a doc]
_documentStore.PersistToDisk(doc);
}
}
I think it's decent, as the code to save things is hidden in DocumentStore
. But we can take it one step further, and remove the call _documentStore.PersistToDisk(doc);
to another class, like this:
public class DocCreatorWorkflow
{
private IDocumentStore _documentStore;
public DocCreatorWorkflow(IDocumentStore documentStore)
{
_documentStore = documentStore;
}
public void CreateAndSave()
{
var docCreator = new DocCreator();
var doc = docCreator.Create();
_documentStore.PersistToDisk(doc);
}
}
In the example above I've created another class, which calls two lower
classes, and so becomes responsible for the 'workflow'. It might be cleaner, but it also complicates things more. Doesn't it?
Or should I always go for the second option?