Top Banner
ADVANCED APPLICATION ARCHITECTURE I - Layers Matthias Noback @matthiasnoback
54

Advanced Application Architecture (workshop slides)

Apr 05, 2017

Download

Software

matthiasnoback
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Advanced Application Architecture (workshop slides)

ADVANCED APPLICATION

ARCHITECTUREI - Layers

Matthias Noback @matthiasnoback

Page 2: Advanced Application Architecture (workshop slides)

matthiasnoback/layers-ports-and-adapters-

workshopClone from GitHub

Follow the instructions in README.md

Page 3: Advanced Application Architecture (workshop slides)

ARCHITECTUREDecisions about coupling and cohesion

Page 4: Advanced Application Architecture (workshop slides)

COUPLINGHow are things linked to each other?

Page 5: Advanced Application Architecture (workshop slides)

COHESIONWhich things belong together?

Page 6: Advanced Application Architecture (workshop slides)

COHESIONWhich things belong together?

www.youtube.com/watch?v=N_7DPyxzUzc

Page 7: Advanced Application Architecture (workshop slides)

LAYERED ARCHITECTUREAn answer to both questions

Page 8: Advanced Application Architecture (workshop slides)

LAYERSHelp you protect what's in a deeper layer

Page 9: Advanced Application Architecture (workshop slides)

LAYERSAllow you to define dependency rules

Page 10: Advanced Application Architecture (workshop slides)

LAYERSDefine the right place to put things

Page 11: Advanced Application Architecture (workshop slides)

TRADITIONAL LAYERING

view model

data

Page 12: Advanced Application Architecture (workshop slides)

LAYERSHorizontal division (as opposed to...)

Page 13: Advanced Application Architecture (workshop slides)

USE CASESVertical division

Page 14: Advanced Application Architecture (workshop slides)

LAYERSRendered as circles

Page 15: Advanced Application Architecture (workshop slides)

CLEAN ARCHITECTUREOr "union" architecture

Page 16: Advanced Application Architecture (workshop slides)

COHESIONA basic set of layers

domain application

infrastructure

Page 17: Advanced Application Architecture (workshop slides)

COUPLINGThe dependency rule

Layers should only depend on deeper layers

Page 18: Advanced Application Architecture (workshop slides)

COUPLINGDependency inversion principle

Classes should always depend on things that are more abstract

Page 19: Advanced Application Architecture (workshop slides)

COUPLINGDependency inversion principle

low-levelconcrete class specific

abstract interface generic high-level

Page 20: Advanced Application Architecture (workshop slides)

COUPLINGDependency inversion principle

use

Page 21: Advanced Application Architecture (workshop slides)

COUPLINGDependency inversion principle

use implement

Page 22: Advanced Application Architecture (workshop slides)

COUPLINGIs about dependencies in code

Use Dependency Injection

Page 23: Advanced Application Architecture (workshop slides)

LAYER CONVENTIONSDomain layer

Domain model:

➤ Entities

➤ Value objects

➤ Domain services

➤ Factories

Business logic

Decisions

Data

State

Behavior

Page 24: Advanced Application Architecture (workshop slides)

LAYER CONVENTIONSApplication layer

➤ Find an object

➤ Change something

➤ Notify something

➤ Get some information

Use cases

Orchestration

Page 25: Advanced Application Architecture (workshop slides)

LAYER CONVENTIONSInfrastructure layer

Communication with:

➤ HTTP client

➤ Database

➤ Filesystem

➤ Email server

➤ Message broker

Connecting the application to

the world outside

Page 26: Advanced Application Architecture (workshop slides)

assignment/01.mdLayers

Page 27: Advanced Application Architecture (workshop slides)

ADVANCED APPLICATION

ARCHITECTUREII - Ports & adapters

Page 28: Advanced Application Architecture (workshop slides)

MESSAGING... is the big idea

Page 29: Advanced Application Architecture (workshop slides)

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

Web

Database

Page 30: Advanced Application Architecture (workshop slides)

PORTS... AND ADAPTERSTranslation

HTTP

SQL

Page 31: Advanced Application Architecture (workshop slides)

HEXAGONAL ARCHITECTURESame thing!

Web

Persistence

Page 32: Advanced Application Architecture (workshop slides)

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

HTTP

SQL

!

!

Page 33: Advanced Application Architecture (workshop slides)

assignment/02.mdPorts

Page 34: Advanced Application Architecture (workshop slides)

PORT ADAPTERS...in the Infrastructure layer

Page 35: Advanced Application Architecture (workshop slides)

APPLICATION SERVICES... in the Application layer

Page 36: Advanced Application Architecture (workshop slides)

DOMAIN MODELin the Domain layer

Page 37: Advanced Application Architecture (workshop slides)

APPLICATION SERVICESDelivery-mechanism agnostic

Page 38: Advanced Application Architecture (workshop slides)

assignment/03.mdInput adapters

Page 39: Advanced Application Architecture (workshop slides)

VALIDATIONAt different levels

Structural validation of messages

User-friendly input validation

Domain invariant protection

Page 40: Advanced Application Architecture (workshop slides)

assignment/04.mdInput validation

Page 41: Advanced Application Architecture (workshop slides)

APPLICATION SERVICESTransactional consistency

Page 42: Advanced Application Architecture (workshop slides)

assignment/05.mdOutput adapter

Page 43: Advanced Application Architecture (workshop slides)

assignment/06.mdA hidden dependency on the persistence mechanism

Page 44: Advanced Application Architecture (workshop slides)

ADVANTAGES OF PORTS & ADAPTERS

Offers insight into the application

Isolates the low-level details

Allows for alternative implementations

Helps with testing

Page 45: Advanced Application Architecture (workshop slides)

ADVANCED APPLICATION

ARCHITECTUREIII - Testing

Page 46: Advanced Application Architecture (workshop slides)

UNIT TESTSTesting your units of code

One class at a time

No IO

No setup required

Mocking only dependencies "you own"

Page 47: Advanced Application Architecture (workshop slides)

INTEGRATION TESTSTesting your adapters

Maybe multiple classes

Including IO

Some setup required

Mocking no dependencies

Page 48: Advanced Application Architecture (workshop slides)

ACCEPTANCE TESTSTesting your application services

Multiple classes

Use cases

Infrastructure stand-ins

Page 49: Advanced Application Architecture (workshop slides)

SYSTEM TESTSTesting your application end-to-end

The real deal

Page 50: Advanced Application Architecture (workshop slides)

TESTING PYRAMIDMake it well-balanced

Unit tests

Integration tests

System tests

Page 51: Advanced Application Architecture (workshop slides)

assignment/07.mdDifferent types of tests

Page 52: Advanced Application Architecture (workshop slides)

assignment/08.mdA test double for the Persistence port

Page 53: Advanced Application Architecture (workshop slides)

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

Page 54: Advanced Application Architecture (workshop slides)

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