Book Image

Designing Hexagonal Architecture with Java

By : Davi Vieira
Book Image

Designing Hexagonal Architecture with Java

By: Davi Vieira

Overview of this book

Hexagonal architecture enhances developers' productivity by decoupling business code from technology code, making the software more change-tolerant, and allowing it to evolve and incorporate new technologies without the need for significant refactoring. By adhering to hexagonal principles, you can structure your software in a way that reduces the effort required to understand and maintain the code. This book starts with an in-depth analysis of hexagonal architecture's building blocks, such as entities, use cases, ports, and adapters. You'll learn how to assemble business code in the Domain hexagon, create features by using ports and use cases in the Application hexagon, and make your software compatible with different technologies by employing adapters in the Framework hexagon. Moving on, you'll get your hands dirty developing a system based on a real-world scenario applying all the hexagonal architecture's building blocks. By creating a hexagonal system, you'll also understand how you can use Java modules to reinforce dependency inversion and ensure the isolation of each hexagon in the architecture. Finally, you'll get to grips with using Quarkus to turn your hexagonal application into a cloud-native system. By the end of this hexagonal architecture book, you'll be able to bring order and sanity to the development of complex and long-lasting applications.
Table of Contents (21 chapters)
1
Section 1: Architecture Fundamentals
7
Section 2: Using Hexagons to Create a Solid Foundation
12
Section 3: Becoming Cloud-Native

Defining entities and specifications

Once we have created all the value objects, we can start to think about how to represent the elements in entities that have an identity. Also, we need to develop specifications to define business rules that govern constraints, which the entities should obey.

Remember that what characterizes an entity is its identity and the presence of business rules and data. In the topology and inventory system, we have as entities Equipment, Router, and Switch.

Inside the domain Java module we created previously, we'll add the entities classes within a package called entity.

The Equipment and Router abstract entities

Both router and switch are different types of network equipment, so we'll start by creating an Equipment abstract class, as follows:

package dev.davivieira.topologyinventory.domain.entity;
import dev.davivieira.topologyinventory.domain.vo.IP;
import dev.davivieira.topologyinventory.domain.vo.Id;
import dev.davivieira.topologyinventory...