Advanced Application Architecture (workshop slides)

Post on 05-Apr-2017

98 views 3 download

Transcript of Advanced Application Architecture (workshop slides)

ADVANCED APPLICATION

ARCHITECTUREI - Layers

Matthias Noback @matthiasnoback

matthiasnoback/layers-ports-and-adapters-

workshopClone from GitHub

Follow the instructions in README.md

ARCHITECTUREDecisions about coupling and cohesion

COUPLINGHow are things linked to each other?

COHESIONWhich things belong together?

COHESIONWhich things belong together?

www.youtube.com/watch?v=N_7DPyxzUzc

LAYERED ARCHITECTUREAn answer to both questions

LAYERSHelp you protect what's in a deeper layer

LAYERSAllow you to define dependency rules

LAYERSDefine the right place to put things

TRADITIONAL LAYERING

view model

data

LAYERSHorizontal division (as opposed to...)

USE CASESVertical division

LAYERSRendered as circles

CLEAN ARCHITECTUREOr "union" architecture

COHESIONA basic set of layers

domain application

infrastructure

COUPLINGThe dependency rule

Layers should only depend on deeper layers

COUPLINGDependency inversion principle

Classes should always depend on things that are more abstract

COUPLINGDependency inversion principle

low-levelconcrete class specific

abstract interface generic high-level

COUPLINGDependency inversion principle

use

COUPLINGDependency inversion principle

use implement

COUPLINGIs about dependencies in code

Use Dependency Injection

LAYER CONVENTIONSDomain layer

Domain model:

➤ Entities

➤ Value objects

➤ Domain services

➤ Factories

Business logic

Decisions

Data

State

Behavior

LAYER CONVENTIONSApplication layer

➤ Find an object

➤ Change something

➤ Notify something

➤ Get some information

Use cases

Orchestration

LAYER CONVENTIONSInfrastructure layer

Communication with:

➤ HTTP client

➤ Database

➤ Filesystem

➤ Email server

➤ Message broker

Connecting the application to

the world outside

assignment/01.mdLayers

ADVANCED APPLICATION

ARCHITECTUREII - Ports & adapters

MESSAGING... is the big idea

PORTS (COHESION)Web, CLI, test client, messages, database queries

Web

Database

PORTS... AND ADAPTERSTranslation

HTTP

SQL

HEXAGONAL ARCHITECTURESame thing!

Web

Persistence

PORTS... AND ADAPTERS(De)serialization, translation, structural validation

HTTP

SQL

!

!

assignment/02.mdPorts

PORT ADAPTERS...in the Infrastructure layer

APPLICATION SERVICES... in the Application layer

DOMAIN MODELin the Domain layer

APPLICATION SERVICESDelivery-mechanism agnostic

assignment/03.mdInput adapters

VALIDATIONAt different levels

Structural validation of messages

User-friendly input validation

Domain invariant protection

assignment/04.mdInput validation

APPLICATION SERVICESTransactional consistency

assignment/05.mdOutput adapter

assignment/06.mdA hidden dependency on the persistence mechanism

ADVANTAGES OF PORTS & ADAPTERS

Offers insight into the application

Isolates the low-level details

Allows for alternative implementations

Helps with testing

ADVANCED APPLICATION

ARCHITECTUREIII - Testing

UNIT TESTSTesting your units of code

One class at a time

No IO

No setup required

Mocking only dependencies "you own"

INTEGRATION TESTSTesting your adapters

Maybe multiple classes

Including IO

Some setup required

Mocking no dependencies

ACCEPTANCE TESTSTesting your application services

Multiple classes

Use cases

Infrastructure stand-ins

SYSTEM TESTSTesting your application end-to-end

The real deal

TESTING PYRAMIDMake it well-balanced

Unit tests

Integration tests

System tests

assignment/07.mdDifferent types of tests

assignment/08.mdA test double for the Persistence port

assignment/09.md An acceptance test for the application layer

A WELL-BALANCED TEST SUITE

Adapters can be easily replaced

Test suite is fast

Feedback is quick

Small amount of fragile tests

Enables continuous delivery