Back to articles
Ports and Adapters: The Pattern Your Architecture Has Been Missing

Ports and Adapters: The Pattern Your Architecture Has Been Missing

via Dev.to PythonPablo Ifrán

In the last post you counted your OrderService 's external dependencies. If you got anything higher than zero, this post is for you. We named the problem. Now let's name the solution. It Has a Name The pattern is called ports and adapters also known as hexagonal architecture, coined by Alistair Cockburn in 2005. The name has stuck around because the idea is genuinely useful: your application core should communicate with the outside world through well-defined boundaries, not direct dependencies. That's the theory. Here's what it actually means in code. What a Port Is A port is an interface owned by your domain. It says: "I need something that can do X. I don't care how." from typing import Protocol , Optional from app.domain.models import Order , Customer class CustomerRepository ( Protocol ): def find_by_id ( self , customer_id : str ) -> Optional [ Customer ]: ... class OrderRepository ( Protocol ): def save ( self , order : Order ) -> Order : ... Notice what these interfaces don't me

Continue reading on Dev.to Python

Opens in a new tab

Read Full Article
2 views

Related Articles