Cracow, April 2017

Keep it clean. Public enemy No. 1, mid-sized building blocks and hexagonal architecture in real life

Do you know why the default scope in Java is package-private? Because that's what designers thought should be the most popular scope. Is that the scope you most often see? Adam Tornhill's research shows, that it's not. Java devs recognise only private and public access, which makes them particularly bad at mid-size building blocks. And so our projects end up being hard to put into your head. Hard to reason about. Entanglement instead of encapsulation. People even register every possible class in an IoC container, because of how much they do not understand package encapsulation. 

Or how about inheritance? James Gosling asked in 2001 about what he would do differently if he had a chance to recreate Java, said he would probably remove class inheritance. We are in 2016, having lambdas, defaults on interfaces, AOP and other tricks, but developers still prefer to just add another abstract class to their code. Gonna be fun navigating those seven layers of hell when you read it. Ok, maybe it's not THAT bad, but it's not much better either. The problem of course, is that we all start with tutorials, which cut corners for brevity. And we don't pay attention to those small problems till they hit us hard.  

Let's see how we can make our situation a little bit better, using Domain Driven Design, package-private scope, sensible packaging structure, CQRS on microservices, and finally: hexagonal architecture. Because it is actually easier, than not doing it. Real life project examples included.

Join! SIGN UP TO OUR newsletter!
Jakub Nabrdalik

A software developer with 14 years of professional experience in IT, as an architect, programmer, designer, analyst, team leader, project manager, development department manager. Gives workshops on software Craftsmanship, Domain Driven Design, Test-driven development and Spring. Team leader at Allegro. More at