Slide 1

Slide 1 text

Hexagonal Architecture (A.K.A Ports & Adapters) Cherif BOUCHELAGHEM

Slide 2

Slide 2 text

What is architecture?

Slide 3

Slide 3 text

What is architecture? “Is the art of drawing lines” Robert C. Martin (Uncle Bob)

Slide 4

Slide 4 text

What is architecture? Those lines generally represent boundaries

Slide 5

Slide 5 text

What is hexagonal architecture?

Slide 6

Slide 6 text

Hexagonal Architecture: What is it? “Create your application to work without either a UI or a database so you can run automated regression-tests against the application, work when the database becomes unavailable, and link applications together without any user involvement.” Alistair Cockburn: Hexagonal architecture

Slide 7

Slide 7 text

The web is delivery mechanism

Slide 8

Slide 8 text

The delivery mechanism is detail

Slide 9

Slide 9 text

Database is detail

Slide 10

Slide 10 text

Hexagonal Architecture: What is it? Drawing from the the original article. Each facet of the hexagon represents a port (a technology-independent protocol capturing a reason for a discussion)

Slide 11

Slide 11 text

Hexagonal Architecture: What is it? Ports, are abstractions on the boundaries. Adapters, are implementations of the given ports.

Slide 12

Slide 12 text

Hexagonal Architecture: What is it? - Ports: Are abstraction defined by the application - Adapters: are the implementation of the ports (abstraction) that connect the application with the outside world. The outside world is anything that is not really important to solve the problem we trying to solve: Database, UI (Delivery mechanism), frameworks (Mobile, web, … etc)

Slide 13

Slide 13 text

Hexagonal Architecture: What is it? We can have more than just 6 facets of the hexagon

Slide 14

Slide 14 text

About unit tests A test is not a unit test if: - It talks to a database - It communicates across the network - It touches the file system - You have to do things to your environment to run it (eg, change config files, comment line) - Tests that do this are integration tests.

Slide 15

Slide 15 text

Hexagonal Architecture: What is it?

Slide 16

Slide 16 text

Why?

Slide 17

Slide 17 text

Hexagonal architecture: Why? Allow an application to equally be driven by users, programs, automated test or batch scripts, and to be developed and tested in isolation from its eventual run-time devices and databases.

Slide 18

Slide 18 text

About unit tests

Slide 19

Slide 19 text

About unit tests For isolation usually people talk about mocks, in reality mocks are one of the test doubles that help to run make unit tests: - Mock - Fake - Spy - Stub - Dummy

Slide 20

Slide 20 text

The problem to solve in this workshop

Slide 21

Slide 21 text

Calculate product taxes - Product has a category - Every category of products has its own tax rate (.17) - The tax calculation is based on simple formula: Product base cost + (product base cost * category tax rate) Source Code