Introduction: Hexagonal Architecture—Decoupling External Systems

Get an introduction to what you’ll learn in this chapter.

We'll cover the following

We’ve already learned how to write tests using the Arrange-Act-Assert template. We’ve also learned about some software design principles, known as the SOLID principles, that help us break our software down into smaller components. Finally, we’ve learned how test doubles can stand in for collaborating components to make FIRST unit tests easier to write.

Hexagonal architecture

In this chapter, we’re going to combine all those techniques into a powerful design approach known as hexagonal architecture. Using this approach, we‘ll benefit from getting more of our application logic under unit tests and reducing the number of integration and end-to-end tests required. We’ll build in a natural resilience to changes outside our application.

Development chores such as changing a database supplier will be simplified, by having fewer places where our code needs to be changed. We’ll also be able to unit test across larger units, bringing some tests that require end-to-end testing in other approaches under unit tests instead.

Chapter goals

In this chapter, we’ll cover the challenges posed by external systems, such as environmental issues and uncertain data, while mastering robust software development and testing. We'll also dive into enhancing testability and maintainability through dependency inversion within the hexagonal architecture, abstracting external systems, refining the domain model, and optimizing testing efficiency with FIRST unit tests.

Get hands-on with 1400+ tech skills courses.