<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Martin Haft on Medium]]></title>
        <description><![CDATA[Stories by Martin Haft on Medium]]></description>
        <link>https://medium.com/@martin.haft?source=rss-1c89c8bbeaa2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ap-tbBFfyXE_ZPyAc3KPsA.png</url>
            <title>Stories by Martin Haft on Medium</title>
            <link>https://medium.com/@martin.haft?source=rss-1c89c8bbeaa2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 20:01:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@martin.haft/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Hexagonal Architecture at its core is based on Dependency Inversion]]></title>
            <link>https://techblog.unite.eu/hexagonal-architecture-at-its-core-is-based-on-dependency-inversion-a8a6ef7ac38b?source=rss-1c89c8bbeaa2------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8a6ef7ac38b</guid>
            <category><![CDATA[dependency-inversion]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[hexagonal-architecture]]></category>
            <dc:creator><![CDATA[Martin Haft]]></dc:creator>
            <pubDate>Wed, 19 Jun 2024 09:42:02 GMT</pubDate>
            <atom:updated>2024-06-26T05:26:28.089Z</atom:updated>
            <content:encoded><![CDATA[<h3>Summary</h3><p>I want to show that hexagonal architecture, also known as “ports and adapters”, fundamentally uses the dependency inversion principle for the outgoing ports. The need to emphasize this stems from several discussions about hexagonal architecture where this characteristic of the outgoing ports was not so explicitly clear.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0oaaog_XCPsRHaSoUhUzvA.jpeg" /></figure><h3>Interview Insights on SOLID Principles</h3><p>In our job interviews, we often discuss the SOLID principles, especially focusing on the “D”. Many mistakenly think it stands for “dependency injection,” but it actually means “dependency inversion.” Understanding dependency inversion is essential, even to properly use dependency injection. Yet, few candidates can accurately explain what dependency inversion is. Thus I’d like first to clarify the dependency inversion principle.</p><h3>Clarifying Dependency Inversion</h3><p>One of the clearest definitions I’ve encountered is (<a href="https://levelup.gitconnected.com/clean-architecture-86c4f03e4771">https://levelup.gitconnected.com/clean-architecture-86c4f03e4771</a>)<em>:</em></p><p><strong><em>High-level modules should not depend on low-level details. Instead, they should depend on abstractions that are implemented by the low-level modules. Thus, inverting the direction of the dependencies.</em></strong></p><h3>Breaking Down the Concept</h3><ul><li><em>Modules</em>: Assumes some level of modularisation.</li><li><em>High-level modules: </em>Typically, these are the core business functionalities in our software.</li><li><em>should not depend on low-level</em> <em>details</em>: supporting modules or technical modules (e.g. the implementation of a persistence layer).</li></ul><p>“A high-level module should not depend on low-level details” in UML notation this could be expressed like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R9Ls8SzNl-5_O-GjqJ1__w.jpeg" /></figure><ul><li><em>Instead, they should depend on abstractions:</em> In object-oriented programming, abstractions are commonly represented by interfaces.</li><li><em>that are implemented by the low-level modules:</em> High-level modules should interact with these interfaces rather than direct implementations. Thus the dependency is to one or more interfaces.</li></ul><p>One possible UML notation would look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q3nZ2VEvcDUpPGWMNhjCyA.jpeg" /></figure><ul><li><em>Thus, inverting the direction of the dependencies.</em>: really? Doesn’t look like that!</li></ul><p>Looks like a low-level module provides a service that is used by a high-level module. So the high-level module still depends on the low-level module. It’s better than before because the high-level module depends only on the interface/abstraction, not on the implementation, but the dependency is not inverted. What’s wrong with it?</p><h3>The Key Insight</h3><p>There is a piece of information missing: What’s crucial is identifying <strong>who</strong> defines the interface. It’s the high-level module that specifies the interface, not the low-level one. <strong>And that’s the clue!</strong></p><p>In UML this is expressed by an required interface with a half-cycle:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ii49RGRi-6yqpbS2xbLjNw.jpeg" /></figure><h3>Hexagonal Architecture Explained</h3><p>Hexagonal Architecture is based mainly on two concepts:</p><ul><li>do not pollute domain knowledge with technical implementations, i.e. separate business implementation and technical implementation</li><li>organise dependencies outside in, i.e. the domain knowledge has no idea of the technical implementations, the technical implementations adapt to the needs of the domain implementation</li></ul><p>To ensure this, one has to invert the dependency of the outgoing communication (secondary ports), i.e. the dependencies are inverted compared to the data flow.</p><h3>Conclusion</h3><p>In a hexagonal architecture for outgoing communication (i.e. the module needs a service), instead of using a service directly through a low-level interface, you define your needed service through your own interface (your port) and then implement an adapter for the low-level service provider (like a database). This arrangement allows high-level components (e.g. the domain knowledge) to remain isolated (it’s completely programmed against its own interface) from changes in low-level implementations, promoting flexibility, maintainability and testability.</p><p>BTW: The same is true for onion architecture or for clean architecture. Both at their core are based on dependency inversion. With ports and adapters as an example, it’s just easy to see.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8a6ef7ac38b" width="1" height="1" alt=""><hr><p><a href="https://techblog.unite.eu/hexagonal-architecture-at-its-core-is-based-on-dependency-inversion-a8a6ef7ac38b">Hexagonal Architecture at its core is based on Dependency Inversion</a> was originally published in <a href="https://techblog.unite.eu/">Unite tech blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>