The Hexagonal Architecture
The Hexagonal Architecture is due to Alistair Cockburn, who later renamed it “Ports and Adapters Architecture”.
Briefly, in this architecture you aim to make your domain model independent from low level concerns such as databases, network services, GUIs and other things “external” to the core of the application. It is closely related to the Dependency Inversion principle.
I found that the HA is a very good way of structuring a Java application. The benefits are that your code becomes easier to test, easier to change, and easier to understand.
I created a little exercise to explain how the HA works. It is described in an old blog post, and it was performed at the Milano XP User Group twice, at the XP Days Benelux 2009, and at XP Day London 2009. I also used it for internal training in Sourcesense.
The Birthday Greetings Kata
- A short essay
- The slides from the presentation
- The source code on Github
Other references
- Alistair Cockburn on the Hexagonal Architecture
- A more recent video with Alistair Cockburn
- Robert Martin on the Dependency Inversion Principle (pdf)
- Miško Hevery on Interfacing with hard-to-test third party code.
- Miško Hevery on Dependency Injection, which is related to the Dependency Inversion Principle (but is not the same thing!)
- Kevin Rutherford wrote many posts on the HA, and my favourite is this one