2. Agenda
● The problem
● The idea
● The aims
● Evolution of an existing application
● The concepts
● Show me the code
2
3. The problem
Over time core business logic of an application becomes tightly coupled with
various libraries, frameworks and technologies making it harder to evolve and test.
Challenges:
● Long lasting product that needs to keep up with changing customer needs
and evolution of technology.
● Ability to change core logic confidently with 100% unit test coverage.
● Ability to switch third party codes easily to avoid obsolete code due to
technology/vendor lock-down.
3
4. The idea
Ports and Adapters Architecture (Alistair Cockburn)
"Allow an application to equally be driven by users, programs, automated test or
batch scripts, and to be developed and tested in isolation from its eventual run-
time devices and databases."
This architecture is also known as:
● Hexagonal Architecture
● Plug-in Architecture
4
5. The aims
● Decoupling application's core business logic from the services it uses.
● Allowing different services to be plugged in.
● Allowing the application to be run without these services.
● Allowing it to become framework agnostic.
5
6. An existing application (order processing)
Here core business logic is coupled with UI
and various libraries, frameworks and
technologies:
● Leakage of external libraries and
technologies in the core logic by direct
dependency.
● Leakage of core logic in the UI which is
not reusable in other UI.
● Leakage of the UI into the core logic.
6
Core
Application
Logic
API
Controllers
Console
Commands
GUI
Controllers
Payment
Shipping
Notification
Data Access
(ORM)
7. Evolution using ports and adapters
7
Core
Application
Logic
API
Controllers
Console
Commands
GUI
Controllers
Payment
Shipping
Notification
Data Access
(ORM)
Primary/Driving Adapters Secondary/Driven Adapters
8. The concepts
● Core as the central artefact of a system.
● All input and output reaches/leaves the core through a port that isolates the
core from external tools, technologies and delivery mechanisms.
● The core should have no knowledge of who/what is sending input or receiving
its output.
● This is intended to provide some protection against the evolution of
technology.
8