I'm trying out a new code structure where I'm splitting all my giant repositories and factories into loads of smaller classes each with a single responsibility. And on top of this I'm using verbs for class names as I think that it's the best way to describe exactly what each class is meant for.
Each class has only one public method (called "Execute"), but often has private methods and sometimes a constructor with arguments.
Examples:
Before:
class DocumentRepository {
public List<Document> GetDocuments()
public void SaveDocument(Document document)
public Document CopyDocument(int id)
}
After:
class GetDocuments {
public List<Document> Execute()
}
class SaveDocument {
public void Execute(Document document)
}
class CopyDocument {
public Document Execute(int id)
}
One benefit of this structure is that I'm much more willing to split the functionality of the public methods into multiple private methods (much easier to read and manage). Before this would increase the clutter in the repository but now the private methods are contained within their separate classes.
I have always read that classes should have nouns as names but when a class only has one use it seems better to name it by what it does.
Question:
Is this a bad idea (both the separation and the naming)? And if so, what is a better way of creating this separation and avoiding large classes?
Edit: It should be noted that I have come to these (weird) ideas from a Command-Query perspective. So maybe it makes most sense to compare it to that instead of repositories.