paint-brush
Hexagonal Architecture: Introduction Part Iby@vijay-aneryae
4,490 reads
4,490 reads

Hexagonal Architecture: Introduction Part I

by Vijay AnerayeFebruary 1st, 2020
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

This article is for sharing my understanding about Ports & Adapters pattern (also known as Hexagonal Architecture) Alistair Cockburn's aim was to use architecture to prevent business logic from infrastructure or framework. In Next Part I would like to run through Use Case using hexagonal architecture. I hope this article will help you understand idea of hexagonal Architecture and who they are comes together I’ll be glad for any feedback! In next part we will run through use Case using Hexagonal architecture using the subject.

Company Mentioned

Mention Thumbnail
featured image - Hexagonal Architecture: Introduction  Part I
Vijay Aneraye HackerNoon profile picture

This article is for sharing my understanding about Ports & Adapters pattern (also known as Hexagonal Architecture), hoping it can be helpful to someone interested in this subject.

Introduction

Documented in 2005 by Alistair Cockburn, Hexagonal Architecture (is also called as Ports & Adapters pattern ) is a architectural pattern used in software design that promotes decoupling from technology and frameworks.

The hexagonal architecture is an attempt to avoid known structural pitfalls in layered architecture.

The idea of Hexagonal Architecture ( Ports & Adapters pattern) is

  • create loosely coupled application components that can be easily connected to their software environme
  • to makes components exchangeable at any level so that it could be run by different kinds of clients (humans, tests cases, other applications,…)
  • it could be tested in isolation from external devices of the real world that the applica

Pitfalls of layered architecture

In layered architecture, over a period of time all the projects get into the problem of excessive coupling across layers.

Architecture

Alistair Cockburn'a aim was to use architecture to prevent business logic from infrastructure or framework,He accordingly drew application domains as hexagonal shapes.

Imagine a hexagon, here the hexagon is the application itself. Inside the hexagon we just have the things that are important for the business problem that the application is trying to solve.

The hexagon contains the business logic, with no references to any technology, framework or real world device. 

In other word, in hexagon, anything inside the hexagon must be free from technology concerns,So the application is technology agnostic.

Outside the hexagon we have any real world thing that the application interacts with.

Overview of what is the Hexagonal Architecture

  • Inside the Hexagon with all the business models/logics, outside the Hexagon: the infrastructure
  • The dependencies always go from outside toward the inside of the Hexagon, which ensures the isolation of the business domain
  • Hexagon depends on nothing but itself,It must not depend on any technical frameworks

Ports And Adaptors in Hexagonal

Adapters

Adapter is to implement a concrete protocol by which some external system or device can communicate with the application.

An adapter translates between a specific technology and a technology free port.

An adapter is a software component that allows a technology  to interact with a port of the hexagon

In most of cases, REST controller are act as a our primary adapter, providing endpoints accessing domain through port (Interface)

adapter converting a specific technology request into a domain understanding form and pass to the hexagonal through Interface( port)

Ports

Ports are the application boundary, in the picture a port is an edge of the hexagon.

To let the outside to interact with the domain, the Hexagon provides business interfaces(Ports) divided in two categories:

API : Those interfaces are implemented by the Hexagon, are also called 'Inbound interface'

SPI: (Service Provider Interface) is an interface for a functionality, needed by the hexagon for implementing the business logic. It also called outbound interface

Befits of Hexagonal

  1. High Maintainability
  2. Low Technical Debt
  3. Easily incorporates any channels like sql, ftp, Http, Ftp, JMS, etc.
  4. Easily tested because it is easy to create a mock when there is a need to implement the contracts.
  5. Adding new requirements means adding plugins or implementing the contracts.
  6. Proper separation of concern.

Conclusion

This is my understanding about hexagonal architecture. In Next Part I would like to run through Use Case using hexagonal architecture .

If you want to get more information on the topic, read Alistair Cockburn’s original article on the subject

I hope this article will help you understand idea of Hexagonal Architecture and who they are comes together I’ll be glad for any feedback!