<?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 msnr on Medium]]></title>
        <description><![CDATA[Stories by msnr on Medium]]></description>
        <link>https://medium.com/@calmcompiler?source=rss-dedc95b016c5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*RXk1Et9dTvfQVX0-</url>
            <title>Stories by msnr on Medium</title>
            <link>https://medium.com/@calmcompiler?source=rss-dedc95b016c5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 16:31:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@calmcompiler/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[SOLID Principles: The Five Engineering Disciplines That Separate Code From Craftsmanship]]></title>
            <link>https://medium.com/@calmcompiler/solid-principles-the-five-engineering-disciplines-that-separate-code-from-craftsmanship-1fdcd14e105a?source=rss-dedc95b016c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/1fdcd14e105a</guid>
            <category><![CDATA[solid-principles]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[software-architecture]]></category>
            <dc:creator><![CDATA[msnr]]></dc:creator>
            <pubDate>Tue, 09 Jun 2026 08:59:06 GMT</pubDate>
            <atom:updated>2026-06-09T08:59:06.495Z</atom:updated>
            <content:encoded><![CDATA[<h4>Every developer writes code. But not every developer writes code that <em>survives</em>.</h4><p>Some code works today and collapses tomorrow. Some code bends gracefully as requirements evolve. And then there’s the rare kind — the kind that feels almost alive, adapting, extending, and scaling without friction.</p><p>What separates these categories isn’t luck. It’s <strong>discipline</strong>. And in object‑oriented design, that discipline has a name: <strong>SOLID</strong>.</p><p>SOLID isn’t just a set of principles — it’s a philosophy. A way of thinking. A quiet rebellion against brittle architectures and accidental complexity. When applied well, SOLID transforms codebases from rigid monoliths into flexible ecosystems.</p><p>Let’s explore each principle with depth, clarity, and real‑world relevance.</p><h3><strong>1. Single Responsibility Principle — The Discipline of Focus</strong></h3><blockquote>A class should have one, and only one, reason to change.</blockquote><p>SRP is the antidote to “God classes” — those monstrous files that do everything from validation to logging to database access. SRP forces you to ask a simple but profound question:</p><p><strong><em>“What is the true responsibility of this class?”</em></strong></p><h4>Bad Example:</h4><pre>class InvoiceService {<br>    void createInvoice() { }<br>    void sendEmail() { }<br>    void logToFile() { }<br>}</pre><h4>Good Example:</h4><pre>class InvoiceCreator { }<br>class EmailNotifier { }<br>class FileLogger { }</pre><h3>Why it matters</h3><ul><li>Easier testing</li><li>Clearer ownership</li><li>Lower cognitive load</li><li>Faster onboarding</li></ul><p>SRP is the foundation upon which all other principles stand.</p><h3><strong>2. Open/Closed Principle — The Art of Growing Without Breaking</strong></h3><blockquote>Software entities should be open for extension but closed for modification.</blockquote><p>OCP is the principle that separates <strong>scalable systems</strong> from <strong>fragile ones</strong>. It tells you: <em>don’t modify existing code every time requirements change — extend it.</em></p><p><strong>Without OCP:</strong></p><pre>if(type.equals(&quot;EMAIL&quot;)) sendEmail();<br>else if(type.equals(&quot;SMS&quot;)) sendSMS();</pre><p><strong>With OCP:</strong></p><pre>interface Notifier { void send(); }<br>class EmailNotifier implements Notifier { }<br>class SMSNotifier implements Notifier { }</pre><p>Add a new notifier? Just create a new class. No existing code changes.</p><h3>Why it matters</h3><ul><li>Reduces regression bugs</li><li>Encourages plugin‑like architectures</li><li>Makes systems future‑proof</li></ul><p>OCP is the principle that keeps your code from becoming a minefield.</p><h3><strong>3. Liskov Substitution Principle — The Promise of Polymorphism</strong></h3><blockquote>Subtypes must be substitutable for their base types.</blockquote><p>LSP is the principle that ensures inheritance remains a tool — not a trap.If a subclass breaks the expectations of its parent, polymorphism collapses.</p><h4>A classic violation:</h4><pre>class Rectangle { setWidth(); setHeight(); }<br>class Square extends Rectangle { } // breaks behavior</pre><p>A square cannot behave like a rectangle without violating mathematical truth.</p><h3>Why it matters</h3><ul><li>Prevents inheritance abuse</li><li>Ensures predictable behavior</li><li>Makes polymorphism reliable</li></ul><p>LSP is the quiet guardian of object‑oriented integrity.</p><h3><strong>4. Interface Segregation Principle — The Elegance of Precision</strong></h3><blockquote>Clients should not be forced to depend on interfaces they do not use.</blockquote><p>ISP is the cure for bloated interfaces — those “kitchen sink” contracts that force classes to implement methods they don’t need.</p><p><strong>Bad Example:</strong></p><pre>interface Machine {<br>    void print();<br>    void scan();<br>    void fax();<br>}</pre><p><strong>Good Example:</strong></p><pre>interface Printer { void print(); }<br>interface Scanner { void scan(); }<br>interface Fax { void fax(); }</pre><h3>Why it matters</h3><ul><li>Reduces unnecessary coupling</li><li>Improves clarity</li><li>Encourages composability</li></ul><p>ISP is minimalism applied to software design.</p><h3><strong>5. Dependency Inversion Principle — The Architecture of Freedom</strong></h3><blockquote>Depend on abstractions, not concretions.</blockquote><p>DIP is the principle that makes large systems maintainable. It flips the dependency graph upside down:</p><ul><li>High‑level modules should not depend on low‑level modules</li><li>Both should depend on abstractions</li></ul><h3>Example</h3><p><strong>Without DIP:</strong></p><pre>class NotificationService {<br>    EmailNotifier email = new EmailNotifier();<br>}</pre><p><strong>With DIP:</strong></p><pre>class NotificationService {<br>    private final Notifier notifier;<br>}</pre><p>Now the service doesn’t care <em>how</em> notifications are sent — only <em>that</em> they are.</p><h3>Why it matters</h3><ul><li>Enables dependency injection</li><li>Makes systems testable</li><li>Decouples business logic from infrastructure</li></ul><p>DIP is the principle that turns rigid systems into flexible ones.</p><h3>SOLID in the Real World</h3><p>SOLID isn’t academic theory — it’s everywhere:</p><ul><li><strong>Spring Framework</strong> uses DIP and OCP at its core</li><li><strong>Microservices</strong> rely on SRP and ISP</li><li><strong>Clean Architecture</strong> is built on DIP</li><li><strong>Design patterns</strong> like Strategy, Factory, and Adapter are SOLID in action</li></ul><p>SOLID is the invisible scaffolding behind modern software.</p><h3>The Hidden Power of SOLID</h3><p>When you apply SOLID consistently, something magical happens:</p><ul><li>Your classes shrink</li><li>Your abstractions sharpen</li><li>Your architecture breathes</li><li>Your code becomes a system, not a script</li></ul><p>SOLID isn’t about writing more code — it’s about writing <strong>better</strong> code. Code that welcomes change instead of fearing it. Code that grows with your product, not against it. Code that feels like craftsmanship.</p><h3>Final Thoughts</h3><p>SOLID principles are not rules — they’re wisdom. They don’t restrict you — they liberate you. They don’t slow you down — they prevent you from slowing down later.</p><p>In a world where software evolves daily, SOLID is the compass that keeps your architecture pointed toward clarity, maintainability, and elegance.</p><p>If you want to build systems that last, teams that scale, and codebases that don’t collapse under their own weight — start with SOLID.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1fdcd14e105a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Singleton Pattern: The Most Misunderstood Hero of Software DesignOne instance.]]></title>
            <link>https://medium.com/@calmcompiler/the-singleton-pattern-the-most-misunderstood-hero-of-software-designone-instance-c105308fe418?source=rss-dedc95b016c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/c105308fe418</guid>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[singleton-design-pattern]]></category>
            <category><![CDATA[gang-of-four]]></category>
            <dc:creator><![CDATA[msnr]]></dc:creator>
            <pubDate>Tue, 09 Jun 2026 08:32:18 GMT</pubDate>
            <atom:updated>2026-06-09T08:32:18.524Z</atom:updated>
            <content:encoded><![CDATA[<h4>One lifecycle. One place to access it.</h4><p>There’s a quiet character in the world of software design patterns — one that developers love, hate, misuse, defend, and debate in equal measure. That character is the <strong>Singleton</strong>.</p><p>Despite being one of the simplest patterns to explain, the Singleton is also one of the easiest to misuse. It sits at the intersection of convenience and architectural discipline, and how you wield it often says more about your engineering maturity than the code itself.</p><p>In this article, we’ll unpack the Singleton pattern from first principles, explore its real-world relevance, and understand why it continues to matter in modern software ecosystems.</p><h3>Why the Singleton Exists at All</h3><p>Software systems often need <strong>exactly one instance</strong> of something — not two, not five, not “whatever the DI container feels like today.” One.</p><p>Think of:</p><ul><li>A <strong>configuration manager</strong> that loads environment settings</li><li>A <strong>logging engine</strong> writing to a single file</li><li>A <strong>cache</strong> that must remain consistent</li><li>A <strong>connection pool</strong> coordinating access to a database</li></ul><p>These are not objects you want duplicated. They are <strong>global truths</strong> in your application’s universe.</p><p>The Singleton pattern formalizes this idea:</p><blockquote>Guarantee a single instance, and provide a global access point to it.</blockquote><h3>The Essence of the Pattern</h3><p>At its core, the Singleton pattern is built on three pillars:</p><ol><li><strong>A private constructor</strong> Prevents external instantiation.</li><li><strong>A static instance</strong> Lives for the lifetime of the application.</li><li><strong>A public accessor</strong> Returns the same instance every time.</li></ol><p>That’s it. Simple. Elegant. And surprisingly powerful.</p><h3>Implementing the Singleton: The Evolution of Thought</h3><h4>1. Eager Initialization — The Straightforward Approach</h4><pre>public class Logger {<br>    private static final Logger INSTANCE = new Logger();<br>    private Logger() {}<br>    public static Logger getInstance() { return INSTANCE; }<br>}</pre><p>This is the “I don’t want surprises” version. The instance is created at class load time — thread‑safe, predictable, and perfect when the object is lightweight.</p><h4>2. Lazy Initialization — The Tempting but Dangerous One</h4><pre>public class Logger {<br>    private static Logger instance;<br>    private Logger() {}<br>    public static Logger getInstance() {<br>        if (instance == null) instance = new Logger();<br>        return instance;<br>    }<br>}</pre><p>This looks elegant until multiple threads call getInstance() simultaneously. Then chaos ensues.</p><h4>3. Double‑Checked Locking — The Pragmatic Middle Ground</h4><pre>public class Logger {<br>    private static volatile Logger instance;<br>    private Logger() {}<br>    public static Logger getInstance() {<br>        if (instance == null) {<br>            synchronized (Logger.class) {<br>                if (instance == null) instance = new Logger();<br>            }<br>        }<br>        return instance;<br>    }<br>}</pre><p>This version is both <strong>lazy</strong> and <strong>thread‑safe</strong>, without the performance penalty of synchronizing every call.</p><h4>4. Bill Pugh Singleton — The Modern Favorite</h4><pre>public class Logger {<br>    private Logger() {}<br>    private static class Holder {<br>        private static final Logger INSTANCE = new Logger();<br>    }<br>    public static Logger getInstance() {<br>        return Holder.INSTANCE;<br>    }<br>}</pre><p>This approach uses class loading semantics to guarantee thread safety and lazy initialization — no locks, no complexity, no surprises.</p><h3>The Dark Side of Singletons</h3><p>Like any powerful tool, the Singleton can be misused. And misuse leads to architectural debt.</p><h4>1. Hidden Global State</h4><p>Singletons can quietly become dumping grounds for shared state, making debugging a nightmare.</p><h4>2. Tight Coupling</h4><p>Code that depends on a Singleton becomes difficult to test and mock.</p><h4>3. Reduced Flexibility</h4><p>You lose the ability to create multiple configurations or environments.</p><h4>4. Lifecycle Problems</h4><p>Singletons live forever — which is great until they hold onto resources they shouldn’t.</p><h3>When Should You Actually Use a Singleton?</h3><p>Use it when:</p><ul><li>The object represents a <strong>unique system resource</strong></li><li>You need <strong>centralized coordination</strong></li><li>The object is <strong>stateless</strong> or <strong>lightweight</strong></li><li>You’re outside a DI framework like Spring</li></ul><p>Avoid it when:</p><ul><li>You need testability</li><li>You want multiple configurations</li><li>You’re working in a DI‑managed environment</li><li>You’re tempted to store mutable global state</li></ul><h3>Final Thoughts</h3><p>The Singleton pattern is not just a design pattern — it’s a lesson in architectural restraint. It teaches us that <strong>global access</strong> is powerful, but <strong>global state</strong> is dangerous. It reminds us that simplicity can be elegant, but only when used with intention.</p><p>In the right hands, the Singleton is a quiet hero. In the wrong hands, it becomes a silent saboteur.</p><p>Use it wisely.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c105308fe418" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>