Ports & Adapters
Ofir Attal, Front End Developer
linkedin/ofiratt github.com/ofiratt@Ofir_attalofira@wix.com
Hi.
I am Ofir Attal, a Front End Developer
Lithuania
Ukraine
Vilnius
Kiev
Dnipro
Wix Engineering Locations
Israel
Tel-Aviv
Be’er Sheva
Ports & Adapters
Architecture
01
the problem is Not writing code that works.
the problem is writing code that is
easy to Modify.
✔ Maintainable
✔ Scalable
✔ Easy to add / remove features to
you need to understand
that your code will change.
Good code is:
Ports and Adapters Architecture
hexagonal
architecture
Business Logic
Technical Details
Alistair
Cockburn
hexagonal
architecture
Business Logic
Technical Details
Ports & Adaptors
Ports & Adapters
is an architecture, that
prevents technical details
from infiltrating the business
logic.
MotorAdapterAirConditioner Motor
+m: Motor
+turnOn()
+turnOFF()
+motor: MotorAdapter
+cool()
+stop()
+spinCW()
+spinCCW()
implementing the Adapter
pattern Example
...
if(roomTemp > desireeTemp)
motor.turnOn();
...
...
motor.CCW();
...
Business Logic
Ports
Interface - API
The BL “knows it and only it”
Adapters
Implement the port
Keep ‘em Thin!
One for each external system
Business Logic
Ports
Interface - API
The BL “knows it and only it”
Adapters
Implement the port
Keep ‘em Thin!
One for each external system
Ports and Adapters Architecture
▪ Prevent external dependencies
from leaking into the code
▪ Anti-corruption layer
▪ They’re replaceable
Business Logic
how adaptors
help you
Code
Example
02
Tic tac toe
let’s do it!
interface TicTacToePort {
markCell(x, y);
...
}
import javax.swing.JTextField;
AdapterUI implement TicTacToePort {
public markCell(row, column) {
textField[row][column].setText(‘X’);
}
}
CoreLogic() {
TicTacToePort ticTacToePort;
think() {
if …
ticTacToePort.markCell(row, column);
}
}
Tic tac toe
business logic
interface TicTacToePort {
markCell(x, y);
...
}
import javax.swing.JTextField;
AdapterUI implement TicTacToePort {
public markCell(row, column) {
textField[row][column].setText(‘X’);
}
}
CoreLogic() {
TicTacToePort ticTacToePort;
think() {
if …
ticTacToePort.markCell(x, y);
}
}
Tic tac toe
port
interface TicTacToePort {
markCell(row, column;
...
}
import javax.swing.JTextField;
AdapterUI implement TicTacToePort {
public markCell(row, column) {
textField[row][column].setText(‘X’);
}
}
CoreLogic() {
TicTacToePort ticTacToePort;
think() {
if …
ticTacToePort.markCell(x, y);
}
}
Tic tac toe
adapter
UML
BL Low Details
<<Interface>>
Ports & Adapters
TDD
03
Growing Object - Oriented Software, Guided By Tests. Nat Pryce
Easy to classify
incidents
Business
logic
Technical
details
Growing Object - Oriented Software, Guided By Tests. Nat Pryce
Easy to test the BL
in unit tests
Growing Object - Oriented Software, Guided By Tests. Nat Pryce
Easy to validate
assumptions
in integration tests
OUR SOFTWARE WILL NEVER BE PERFECT.
public spinTheRolate(int userBetNumber) {
Random rand;
int rolateNumber = rand.nextInt(36);
if(userBetNumber == rolateNumber) {
system.print.out("user won");
}
else {
system.print.out("user lost");
}
}
code
Violations
public spinTheRolate(int userBetNumber) {
Random rand;
int rolateNumber = rand.nextInt(36);
if(userBetNumber == rolateNumber) {
userNotifications.won();
}
else {
userNotifications.lost();
}
}
interface UserNotifications {
public won();
public lost();
}
UserNotificationUI implements UserNotifications {
public won() { system.print.out("user won"); }
public lost() { system.print.out("user lost"); }
}
code
Violations
private getNewRolateBet() {
Random rand;
return rolateNumber = rand.nextInt(36);
}
public playUserBatFor(int userBetNumber) {
if(userBetNumber == getNewRolateBet())
userNotifications.won();
else
userNotifications.lost();
}
interface UserNotifications {
public won();
public lost();
}
UserNotificationUI implements UserNotifications {
public won() { system.print.out("user won"); }
public lost() { system.print.out("user lost"); }
}
code
Violations
1.
keep the BUsiness
Logic clean!
2.
Keep The adapter
thin
2 takeaways
for ports & adapters
http://wiki.c2.com/?HexagonalArchitecture
http://wiki.c2.com/?PortsAndAdaptersArchitecture
https://spin.atomicobject.com/2013/02/23/ports-adapters-software-architecture/
http://alistair.cockburn.us/Hexagonal+architecture
http://www.natpryce.com/articles/000772.html
https://cleancoders.com/videos/clean-code
SOLID videos - https://cleancoders.com/videos/clean-code/solid-principles
resources
Thank You
linkedin/ofiratt github.com/ofiratt@Ofir_attalofira@wix.com
Q&A
linkedin/ofiratt github.com/ofiratt@Ofir_attalofira@wix.com

More Related Content

PDF
Ports and Adapters Architecture - solid
PDF
Enterprise Tic-Tac-Toe
PPT
Notacion uml
PDF
Dependency inversion using ports and adapters
PDF
Java How To Program Fourth Edition Harvey M. Deitel
PDF
Designing Architecture-aware Library using Boost.Proto
PDF
超級全能危樓改造王 - 增建、改建、打掉重建你的軟體架構?
PPT
Ch08lect3 ud
Ports and Adapters Architecture - solid
Enterprise Tic-Tac-Toe
Notacion uml
Dependency inversion using ports and adapters
Java How To Program Fourth Edition Harvey M. Deitel
Designing Architecture-aware Library using Boost.Proto
超級全能危樓改造王 - 增建、改建、打掉重建你的軟體架構?
Ch08lect3 ud

Similar to Ports and Adapters Architecture (20)

ODP
SOLID refactoring - racing car katas
PDF
Software Engineering :Behavioral Modelling - I Sequence diagram
PPTX
Design Patterns
PDF
Exemplar: Designing Sensor-based interactions by demonstration... (a CHI2007 ...
PDF
Software Engineering : OOAD using UML
PPTX
Object oriented methodology & unified modeling language
PDF
Functional solid
PPT
Itp design patterns - 2003
PPTX
10 Reasons Your Software Sucks - Election 2012 Edition
KEY
Design Patterns Course
PPT
UML Diagrams, examples, descriptions and tutorials
PPT
Ch05lect2 ud
PDF
Software Design Patterns. Part I :: Structural Patterns
PDF
ArashResumeOct15
PDF
Design patters java_meetup_slideshare [compatibility mode]
PPT
P Training Presentation
PDF
Empathic Programming - How to write comprehensible code
PDF
UML profiles for Embedded Systems
PDF
Design Patterns
SOLID refactoring - racing car katas
Software Engineering :Behavioral Modelling - I Sequence diagram
Design Patterns
Exemplar: Designing Sensor-based interactions by demonstration... (a CHI2007 ...
Software Engineering : OOAD using UML
Object oriented methodology & unified modeling language
Functional solid
Itp design patterns - 2003
10 Reasons Your Software Sucks - Election 2012 Edition
Design Patterns Course
UML Diagrams, examples, descriptions and tutorials
Ch05lect2 ud
Software Design Patterns. Part I :: Structural Patterns
ArashResumeOct15
Design patters java_meetup_slideshare [compatibility mode]
P Training Presentation
Empathic Programming - How to write comprehensible code
UML profiles for Embedded Systems
Design Patterns
Ad

Recently uploaded (20)

PDF
Ableton Live Suite for MacOS Crack Full Download (Latest 2025)
PPTX
CNN LeNet5 Architecture: Neural Networks
PDF
DNT Brochure 2025 – ISV Solutions @ D365
PPTX
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
PPTX
Python is a high-level, interpreted programming language
PDF
CCleaner 6.39.11548 Crack 2025 License Key
PDF
Practical Indispensable Project Management Tips for Delivering Successful Exp...
PDF
DuckDuckGo Private Browser Premium APK for Android Crack Latest 2025
DOCX
How to Use SharePoint as an ISO-Compliant Document Management System
PPTX
most interesting chapter in the world ppt
PDF
Introduction to Ragic - #1 No Code Tool For Digitalizing Your Business Proces...
PDF
novaPDF Pro 11.9.482 Crack + License Key [Latest 2025]
PPTX
Cybersecurity-and-Fraud-Protecting-Your-Digital-Life.pptx
PDF
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
PDF
AI/ML Infra Meetup | LLM Agents and Implementation Challenges
PPTX
GSA Content Generator Crack (2025 Latest)
PPTX
4Seller: The All-in-One Multi-Channel E-Commerce Management Platform for Glob...
PPTX
How to Odoo 19 Installation on Ubuntu - CandidRoot
PDF
EaseUS PDF Editor Pro 6.2.0.2 Crack with License Key 2025
PDF
E-Commerce Website Development Companyin india
Ableton Live Suite for MacOS Crack Full Download (Latest 2025)
CNN LeNet5 Architecture: Neural Networks
DNT Brochure 2025 – ISV Solutions @ D365
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
Python is a high-level, interpreted programming language
CCleaner 6.39.11548 Crack 2025 License Key
Practical Indispensable Project Management Tips for Delivering Successful Exp...
DuckDuckGo Private Browser Premium APK for Android Crack Latest 2025
How to Use SharePoint as an ISO-Compliant Document Management System
most interesting chapter in the world ppt
Introduction to Ragic - #1 No Code Tool For Digitalizing Your Business Proces...
novaPDF Pro 11.9.482 Crack + License Key [Latest 2025]
Cybersecurity-and-Fraud-Protecting-Your-Digital-Life.pptx
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
AI/ML Infra Meetup | LLM Agents and Implementation Challenges
GSA Content Generator Crack (2025 Latest)
4Seller: The All-in-One Multi-Channel E-Commerce Management Platform for Glob...
How to Odoo 19 Installation on Ubuntu - CandidRoot
EaseUS PDF Editor Pro 6.2.0.2 Crack with License Key 2025
E-Commerce Website Development Companyin india
Ad

Ports and Adapters Architecture