Michael Nygard writes in Release It!:
Have you ever checked in a commit that had bunch of new files like "Foo", "FooController", "FooFragment", "FooMapper", "FooDTO", and so on? That is evidence of bad layering.
This sounds pretty significant as almost every code base I saw so far looks exactly like this. For example a little web application (in Java implemented with Spring Boot - irrelevant):
com.example.foo └ FooApplication.java └ controller └ FooController.java └ FooDTO.java └ model └ Foo.java └ Foos.java └ repository └ FooRepository.java
Looks like what Nygard is talking about.
What is a better approach here?
- Use the model object
Foodirect in the controller's input/output to eliminate
FooDTO? Sounds not correct.
- Do the domain logic direct in the controller to eliminate domain objects? Sounds horrible.
- Do the persistence direct in the domain object to eliminate the repository? Maybe.
I still don't see an option how to eliminate the controller as a representative of the application layer.
Nygard writes futher in the same paragraph:
What appears as a class in one layer should be mere data to every other layer.
Is this not what
FooDTO is all about?
So what would satisfy Nygard's concerns? Or is that just my misconception?