At first glance, the folks following Java architecture are feeling like they’re ahead. The project on GitHub provides more details about how to handle the web frameworks. But when it comes to implementation, things get difficult and many questions appear. When I was read about Clean Architecture, I came across this discussion on StackExchange, that says: Even if you need put an @Entity annotation of the ORM into your domain object, I'd argue that this does not establish a "mention" of the outer layer. I think we can all agree that this architecture puts us in a pretty ideal position. For example, if your project is big and complex, has a lot of business logic – then the Clean architecture brings clear benefits. I’m not saying annotations are bad, and I’m not saying that ORMs are bad. If you were to create a single UserService instead it would be difficult to tell what kind of operations exist within that service, and you would need to dive into the implementation to understand what the service does. This week, I want to start digging a bit deeper into what makes the Clean Architecture clean and how most Java applications stack-up against it. I could go on and on about this, but the net-net is this: if you have special things you want to do in the view, create abstractions that support those special things that are separate from your Entities. Do the same for the client/view. In Java architecture, source dependencies follow logical flow, but in Clean Architecture source dependencies oppose the direction of logical flow when business logic calls persistence logic. Jigsaw modules allow us to hide implementation details. Here it is again. That is, unless there is a good bit of view logic. Robert C. Martin (aka Uncle Bob) deeply developed his vision of a clean architecture in his book, that I highly recommend. Plus, do you want to have to go change every view when the set of values changes? If that sounds like fun to you, just fill out the following form and click 'Yes! Where do I start? Looking for a Clean Architecture course that covers more than theory? Before you answer, remember that the interfaces for the DAOs are in the persistence project! More than that, what if you wanted to include multiple sets of persistence logic and let the user choose among them? How do I apply Uncle Bob’s principles to the technology I want to use? The inner layers contain domain objects and business rules. Because annotations are just metadata, no code that isn't specifically looking for them will see them. It’s still a bit database focused. To do so, we need to create a config folder that contains the configuration of the app and an application folder that contains code to run the application. So, then, Clean Architecture is a specific way to design an application at its highest levels. It’s important to note that Clean architecture isn’t a silver bullet solution, but can be general, for any platform. That layer is the entire reason our application exists. I kinda expected that ;-) Enough of theory - let’s look at something more practical … It’s pretty easy — we just need to: Here is what the Spring controller looks like: You can find the full example of this application in GitHub using both Spring Boot and Vert.x. Craftsmanship Counts is a botique consultancy offering Agile leadership, development, and clean coding services. That’s really bad. If you work on a new app, there is no good excuse not to structure your code with Clean Architecture in mind. It wound up being a bit longer than I’d imagined, so thanks to those of you who stuck it out to the end. I shared some UML for those that don’t already know it, but just enough to help us understand the diagrams I’ll be sharing. Check out Java Clean Architecture by Example! I think next week will end this series, but I’m not entirely sure. I’m working on something more in-depth, so stay tuned! How do I apply Uncle Bob’s principles to the te… That’s how a layered application architecture works, after all. Take a look at our service and persistence classes. These are also details and not business rules, and will be implemented later in outer layers. Of course, once these values go over the wire, they’re all turned into strings anyway, but some fields you might like to have in an entity may need special attention when being converted, such as “pick one” or “pick many” fields where the entity represents only a single value out of the allowed set. A better approach is to formalize the idea of the selectable list into whatever you return to the view and teach the view to use that abstraction. There really is no good reason all of this information can’t be translated into a form directly consumable by the view and built directly from something originating in the business logic layer.