SlideShare a Scribd company logo
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:
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
▪ 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

Similar to Ports and Adapters Architecture

Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, TuningJava 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
Carol McDonald
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5
PRADEEP
 
NDC 2011, C++ 프로그래머를 위한 C#
NDC 2011, C++ 프로그래머를 위한 C#NDC 2011, C++ 프로그래머를 위한 C#
NDC 2011, C++ 프로그래머를 위한 C#
tcaesvk
 
MASTER-CLASS: "CODE COVERAGE ON Μ-CONTROLLER" Sebastian Götzinger
MASTER-CLASS: "CODE COVERAGE ON Μ-CONTROLLER" Sebastian GötzingerMASTER-CLASS: "CODE COVERAGE ON Μ-CONTROLLER" Sebastian Götzinger
MASTER-CLASS: "CODE COVERAGE ON Μ-CONTROLLER" Sebastian Götzinger
Ievgenii Katsan
 
20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris
imec.archive
 

Similar to Ports and Adapters Architecture (20)

Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, TuningJava 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
 
Porting Motif Applications to Qt - Webinar
Porting Motif Applications to Qt - WebinarPorting Motif Applications to Qt - Webinar
Porting Motif Applications to Qt - Webinar
 
Porting Motif Applications to Qt - Webinar
Porting Motif Applications to Qt - WebinarPorting Motif Applications to Qt - Webinar
Porting Motif Applications to Qt - Webinar
 
Integrating Ansible Tower with security orchestration and cloud management
Integrating Ansible Tower with security orchestration and cloud managementIntegrating Ansible Tower with security orchestration and cloud management
Integrating Ansible Tower with security orchestration and cloud management
 
Verilog presentation final
Verilog presentation finalVerilog presentation final
Verilog presentation final
 
WCF and WF in Framework 3.5
WCF and WF in Framework 3.5WCF and WF in Framework 3.5
WCF and WF in Framework 3.5
 
GraphQL @ Wix
GraphQL @ WixGraphQL @ Wix
GraphQL @ Wix
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5
 
NDC 2011, C++ 프로그래머를 위한 C#
NDC 2011, C++ 프로그래머를 위한 C#NDC 2011, C++ 프로그래머를 위한 C#
NDC 2011, C++ 프로그래머를 위한 C#
 
Internet of Things: Programming on the edge
Internet of Things: Programming on the edgeInternet of Things: Programming on the edge
Internet of Things: Programming on the edge
 
Online test program generator for RISC-V processors
Online test program generator for RISC-V processorsOnline test program generator for RISC-V processors
Online test program generator for RISC-V processors
 
Tdd,Ioc
Tdd,IocTdd,Ioc
Tdd,Ioc
 
IoT Protocols Integration with Vortex Gateway
IoT Protocols Integration with Vortex GatewayIoT Protocols Integration with Vortex Gateway
IoT Protocols Integration with Vortex Gateway
 
Basics of digital verilog design(alok singh kanpur)
Basics of digital verilog design(alok singh kanpur)Basics of digital verilog design(alok singh kanpur)
Basics of digital verilog design(alok singh kanpur)
 
2008 - TechDays PT: Building Software + Services with Volta
2008 - TechDays PT: Building Software + Services with Volta2008 - TechDays PT: Building Software + Services with Volta
2008 - TechDays PT: Building Software + Services with Volta
 
Semplificare l'observability per progetti Serverless
Semplificare l'observability per progetti ServerlessSemplificare l'observability per progetti Serverless
Semplificare l'observability per progetti Serverless
 
TAXTRON Profile_PDF
TAXTRON Profile_PDFTAXTRON Profile_PDF
TAXTRON Profile_PDF
 
A Graphical Way of Thinking About React Designs
A Graphical Way of Thinking About React DesignsA Graphical Way of Thinking About React Designs
A Graphical Way of Thinking About React Designs
 
MASTER-CLASS: "CODE COVERAGE ON Μ-CONTROLLER" Sebastian Götzinger
MASTER-CLASS: "CODE COVERAGE ON Μ-CONTROLLER" Sebastian GötzingerMASTER-CLASS: "CODE COVERAGE ON Μ-CONTROLLER" Sebastian Götzinger
MASTER-CLASS: "CODE COVERAGE ON Μ-CONTROLLER" Sebastian Götzinger
 
20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris
 

Recently uploaded

Recently uploaded (20)

Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Kraków
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting software
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 

Ports and Adapters Architecture