<?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 Ignatij Gichevski on Medium]]></title>
        <description><![CDATA[Stories by Ignatij Gichevski on Medium]]></description>
        <link>https://medium.com/@ignatij.gichevski?source=rss-f210172eed6f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*M6Jxu76li2TRsyij5DCTpA@2x.jpeg</url>
            <title>Stories by Ignatij Gichevski on Medium</title>
            <link>https://medium.com/@ignatij.gichevski?source=rss-f210172eed6f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 14:30:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ignatij.gichevski/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[Using metrics for crafting a better software architecture — the Java and Maven approach]]></title>
            <link>https://medium.com/javarevisited/using-metrics-for-crafting-maintainable-solutions-on-the-long-run-the-maven-way-1a2d84508bf0?source=rss-f210172eed6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a2d84508bf0</guid>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[maven]]></category>
            <dc:creator><![CDATA[Ignatij Gichevski]]></dc:creator>
            <pubDate>Mon, 27 Dec 2021 08:32:00 GMT</pubDate>
            <atom:updated>2021-12-27T21:15:44.815Z</atom:updated>
            <content:encoded><![CDATA[<h3>Using metrics for crafting a better software architecture — the Java and Maven approach</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uOLLqbyfYaJwy8wB1q555Q.jpeg" /></figure><p>Have you ever found yourself in a situation where changing a simple line of code results in a bunch of compilation errors across the whole application?<br>Or introducing a bug some place you would at least expect?<br>Well if you haven’t been there, I have, and let me tell you it’s not pleasant. <br>Not. At. All.</p><p>But the question that we as a team asked is how did we manage to get here?Looking back retrospectively, we followed some common guidelines, had a good test coverage, made sure to establish some good practices beforehand and yet we managed to get to a place where changing one line turns out to be a full three-day effort.</p><p>Good luck explaining that to your manager!</p><p>Let me start from scratch. You’re starting on a new project that starts simple, but things quickly start to escalate and before you know it, you have to establish some ground rules. <br>You probably have some business logic, so you create a module that will wrap that logic, let’s say it <strong>core </strong>module. You will probably also need an API, so you will also add an <strong>API </strong>module. You need security, so you add a <strong>security </strong>module. Not to mention if you’re working with DDD or having a CQRS or Hexagonal architecture, then you will probably end up with a bunch of different modules covering who knows what at the end.</p><p>Don’t get me wrong, that’s probably the right way to go if you want to have a maintainable and scalable solution on the long run. It’s definitely a good approach to separate the various concerns and group the common ones.</p><p>So, what did we do wrong to end up where we did?</p><p>Well, it turns out that it’s not only important to just create different modules and separate the concerns, but also how you connect those modules, how you introduce the dependencies between them.</p><p><a href="https://en.wikipedia.org/wiki/Robert_C._Martin">Robert C.Martin</a> mentioned this problem in his <a href="https://www.goodreads.com/book/show/18043011-clean-architecture">Clean Architecture</a> book and he proposed one solution to it.<br>What he proposed is introducing some kind of metrics based entirely on how the modules of a system are connected between themselves. The purpose of those metrics is to be able to determine how scalable and maintainable a system is.</p><p>In the following part of this article, before diving into a more practical work, I’ll try to do a very brief summary of the theory behind the metrics that Robert Martin explained in much more details in the chapter of his book (yes, obviously I highly recommend reading that one over the following two-minute long TL;DR part).</p><h3>Dependency Management Metrics</h3><p>The Dependency Management metrics are consisted from two principles:</p><ul><li>Stable Dependencies principle</li><li>Stable Abstractions principle</li></ul><p>In the part that follows, we will refer to the term <strong>component </strong>which is practically the equivalent of a Maven module in the Java and Maven ecosystem.</p><h4>Stable Dependencies principle</h4><p><em>“Any component that we expect to be volatile, should not be depended on by a component that’s difficult to change. Otherwise, the volatile component will also be difficult to change.”</em></p><p>What actually makes a component difficult to change (a.k.a “stable”)? <br>Many factors may make a software component difficult to change (size, complexity, clarity, number of components that depend on it…).<br>What we are particularly interested is the last case, when a component has a number of other components that depend on it. A component with lots of incoming dependencies is very hard to change, hence the name “stable” component:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/371/1*e58NTfrtaMR7zyjnoxGrIw.png" /></figure><p>As you might have guessed it already, an “unstable” component is quite the opposite. <br>An “unstable” component is a component which depends on other components and yet no other components depends on it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/331/1*ydczgxX8qO8W-kaqOiYqMw.png" /></figure><p><strong>Instability of component</strong></p><p>We can define the term <strong>Instability</strong><em> </em>of a component as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/1*TfX66zfdedC7yyzohJccuA.png" /></figure><p>Now that we have defined the <strong>Instability</strong>, we can define the actual principle of <strong>Stable Dependencies</strong><em>:</em></p><p><em>“A component should always be dependent of a more stable component.”</em></p><p>On the following image we can see a clear violation of the principle:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*H9H1QSS0bPkpgVMF810bQw.png" /></figure><p>where <strong>Stable Component</strong>(dependent on by two components) depends on unstable<strong> </strong>component(dependent on by only one component — Stable Component).</p><h4><strong>Stable Abstractions principle</strong></h4><p>To be able to define the <strong>Stable Abstractions</strong> principle, we first need to establish the definition of the term — <strong>Abstract component</strong>.</p><p><em>“Abstract component is a component that holds only interfaces or abstract classes.”</em></p><p>These abstract components are very stable and ideal for less stable components to depend on.</p><p>We can define the level of Abstraction of a single component on the following way:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*c4E-QMk5-D-gzY2CxQ_pdg.png" /></figure><p>Now that we have defined the term Abstraction of a component, we can define the <strong>Stable Abstractions </strong>principle:</p><p><em>“A component should always be dependent of a more abstract component.”</em></p><h4>Main Sequence</h4><p>We have defined the two principles, so what’s next? <br>Let’s try to define a connection between the <strong>Instability </strong>and <strong>Abstractness </strong>metrics on an x-y axis:</p><figure><img alt="An X-Y axis of Instability and Abstractness of a component" src="https://cdn-images-1.medium.com/max/522/1*-fwhMiFm8Fki7SVt8pH8Rw.png" /><figcaption>X-Y axis where X-axis is Instability, Y-axis is Abstractness of a component</figcaption></figure><p>If we draw a line between the <em>(0,1)</em> and <em>(1,0)</em> points on the x-y axis stated above, we get a line that’s called the <strong>Main Sequence</strong> line:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*DWjTZWl-OjDKhT29mfSXPw.png" /></figure><p>This line represents a place where all components should be. A component that sits on the <strong>Main Sequence</strong> is neither too abstract, nor is too unstable.</p><p>Now that we have defined where the components should be, it’s time to define where exactly they shouldn’t be, in the so-called <strong>Zones of Exclusions</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*EWlftTrmYjIBAkBTW_QWKQ.png" /><figcaption>Zones of Exclusions</figcaption></figure><p>As we can see there are two zones where we don’t want our components to be:</p><p><strong>Zone of Pain<br></strong>Highly stable and concrete components. This is not desirable because the components that are in this region are very rigid. They cannot be extended because they lack abstractness and they are very difficult to change due to their high stability.</p><p><strong>Zone of Uselessness<br></strong>Highly abstract components, without any dependents, i.e. useless components.</p><p><strong>Distance from Main Sequence<br></strong>Now it’s time to define the metric that corresponds to the distance of how far away is a component from the <strong>Main Sequence</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/308/1*kyZYGmM67Nyxqyf8EU3lnA.png" /></figure><p>Any component that has a <strong>D</strong> metric value that’s not near zero, can be further reexamined and restructured.</p><p>Statistical analysis of a design is also possible by calculating the <strong>mean</strong> and <strong>variance </strong>of all the <strong>D</strong> metrics for the components. <br>A conforming design should have <strong>mean</strong> and <strong>variance</strong> values that are close to zero.</p><h3>Dependency Management Metrics Maven Plugin</h3><p>Hopefully you got the idea from the theoretical part, now it’s time to see how we could actually benefit from these metrics on a more practical level for projects that use Java and Maven.</p><p><a href="https://github.com/ignatij/dependency-management-metrics-maven-plugin"><strong>Dependency Management Metrics</strong></a> is a Maven plugin that calculates and outputs the Dependency Management metrics for each Maven module within a Java multi-module project. The plugin takes into consideration only dependencies which are internal and project-specific, not external dependencies (i.e. Spring).</p><p>The following metrics are taken into consideration for each Maven module:</p><ul><li>Stability metric</li><li>Abstraction metric</li><li>Distance from Main Sequence</li></ul><p>The plugin also outputs the modules present in the <strong>Zone of Pain </strong>and the <strong>Zone of Uselessness</strong> in a separate section, <strong>Zones of Exclusions </strong>section.</p><p>And finally, the plugin can potentially break the Maven build if either the <strong>Stable Dependencies </strong>or <strong>Stable Abstractions </strong>principle is violated.</p><h4>Results</h4><p>Running the plugin in a multi-module Java project produces the following output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gZvSAA5p0LAbmYW3Yveu6A.png" /></figure><p>From the output we can see that some of the modules which are misplaced the most belong in the <strong>Zone Of Pain </strong>section, meaning that they are highly stable modules that clearly lack abstractions.</p><p>What does this mean for us? <br>This practically means that changes in those modules should be as small and as rarely as possible, so we don’t unexpectedly introduce some bugs, build problems or simply increase the headache factor among the developers (and the managers, some time later).</p><h3>Conclusion</h3><p>The plugin itself doesn’t fix the problem for us, its purpose is to point out the spots where we can further act and improve.</p><p>It can act both as a general overview of the current architecture and more importantly, as a guideline for future planned work — be able to recognise if some refactoring or restructuring is needed beforehand, which hopefully on the long run it will contribute to a better, much scalable and maintainable software.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a2d84508bf0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/using-metrics-for-crafting-maintainable-solutions-on-the-long-run-the-maven-way-1a2d84508bf0">Using metrics for crafting a better software architecture — the Java and Maven approach</a> was originally published in <a href="https://medium.com/javarevisited">Javarevisited</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>