<?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 Parth Maru on Medium]]></title>
        <description><![CDATA[Stories by Parth Maru on Medium]]></description>
        <link>https://medium.com/@theparthmaru?source=rss-6dc55053f943------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-Nk4zeXh4RMWodpRBV6D4A.jpeg</url>
            <title>Stories by Parth Maru on Medium</title>
            <link>https://medium.com/@theparthmaru?source=rss-6dc55053f943------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 06:29:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@theparthmaru/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 Part 4: Why the Interface Segregation Principle (ISP) Protects Your Code from…]]></title>
            <link>https://medium.com/@theparthmaru/solid-principles-part-4-why-the-interface-segregation-principle-isp-protects-your-code-from-c09a74c176b3?source=rss-6dc55053f943------2</link>
            <guid isPermaLink="false">https://medium.com/p/c09a74c176b3</guid>
            <category><![CDATA[solid-principles]]></category>
            <category><![CDATA[design-principles]]></category>
            <dc:creator><![CDATA[Parth Maru]]></dc:creator>
            <pubDate>Mon, 29 Dec 2025 21:01:44 GMT</pubDate>
            <atom:updated>2025-12-29T21:01:44.869Z</atom:updated>
            <content:encoded><![CDATA[<h3>SOLID Principles Part 4: Why the Interface Segregation Principle (ISP) Protects Your Code from Unnecessary Dependencies</h3><h3>What the Interface Segregation Principle says?</h3><blockquote>No client should be forced to depend on methods it does not use.</blockquote><p>At first glance, this sounds simple. But in practice, violating ISP is one of the fastest ways to create <strong>rigid, fragile APIs</strong>.</p><h3>The real problem ISP solves</h3><p>As applications grow, interfaces tend to grow with them.</p><p>What often starts as a small, clean interface slowly becomes a <strong>“fat interface”</strong>:</p><ul><li>New features are added.</li><li>New methods are appended.</li><li>Existing clients are forced to adapt.</li></ul><p>Eventually, some classes:</p><ul><li>Implement methods they don’t need.</li><li>Leave methods empty.</li><li>Throw UnsupportedOperationException</li></ul><p>At that point, the <strong>interface itself becomes a liability</strong>.</p><p>ISP exists to prevent exactly this situation.</p><h3>A common misconception ❌</h3><blockquote><em>“ISP means every interface should have only one method.”</em></blockquote><p>This is <strong>not true</strong>. ISP does <strong>not</strong> enforce <em>single-method interfaces</em>.<br>It enforces <strong>single-responsibility interfaces</strong>.</p><p>An interface may have:</p><ul><li>Multiple methods.</li><li>As long as they all belong to <strong>one cohesive role.</strong></li></ul><p>The problem arises when <strong>unrelated responsibilities are grouped together</strong>.</p><h3>Example: The Payment Processor Problem</h3><p>Let’s look at a <strong>payment system</strong> in a backend application.</p><h4>❌ Bad Code — Violating ISP</h4><h4><strong>PaymentProcessor.java</strong></h4><pre>public interface PaymentProcessor {<br>    void processPayment();<br>    void refundPayment();<br>    void generateInvoice();<br>}</pre><p>At first, this looks reasonable.</p><p>Now imagine a class that only supports <strong>payment processing</strong>, not refunds or invoicing:</p><h4>CardPaymentProcessor.java</h4><pre>public class CardPaymentProcessor implements PaymentProcessor {<br><br>    @Override<br>    public void processPayment() {<br>        // process card payment<br>    }<br><br>    @Override<br>    public void refundPayment() {<br>        throw new UnsupportedOperationException(&quot;Refund not supported&quot;);<br>    }<br><br>    @Override<br>    public void generateInvoice() {<br>        throw new UnsupportedOperationException(&quot;Invoice not supported&quot;);<br>    }<br>}</pre><p>This class is now:</p><ul><li>Forced to implement methods it doesn’t need.</li><li>Exposing runtime failures.</li><li>Violating ISP.</li></ul><p>The problem is <strong>not the class,</strong> <strong>the problem is the interface design</strong>.</p><h4>✅ Better Code — Applying ISP</h4><p>Instead of one large interface, we split it by <strong>roles</strong>.</p><pre>public interface PaymentProcessor {<br>    void processPayment();<br>}<br><br>public interface RefundProcessor {<br>    void refundPayment();<br>}<br><br>public interface InvoiceGenerator {<br>    void generateInvoice();<br>}</pre><p>Now classes implement <strong>only what they need</strong>:</p><pre>public class CardPaymentProcessor implements PaymentProcessor {<br><br>    @Override<br>    public void processPayment() {<br>        // process card payment<br>    }<br>}</pre><p>A more advanced implementation can compose multiple roles:</p><pre>public class FullPaymentService implements PaymentProcessor, RefundProcessor, InvoiceGenerator {<br><br>    @Override<br>    public void processPayment() {<br>        // process payment<br>    }<br><br>    @Override<br>    public void refundPayment() {<br>        // handle refund<br>    }<br><br>    @Override<br>    public void generateInvoice() {<br>        // generate invoice<br>    }<br>}</pre><p>Each class now:</p><ul><li>Depends only on what it uses.</li><li>Has no dummy or unsupported methods.</li><li>Is easier to test and maintain.</li></ul><h3>Why ISP matters in real backend systems</h3><p>In real-world backend applications:</p><ul><li>Interfaces are shared across layers.</li><li>Changes ripple through services.</li><li>One bad interface can affect many classes.</li></ul><p>ISP helps in:</p><ul><li>Reducing coupling.</li><li>Making APIs clearer.</li><li>Preventing accidental breaking changes.</li><li>Improving long-term maintainability.</li></ul><p>It complements <strong>SRP, OCP, and LSP</strong> by keeping contracts clean and focused.</p><h3>Final thoughts</h3><p>Clean interfaces lead to:</p><ul><li>Cleaner implementations.</li><li>Clearer intent.</li><li>Safer evolution of your system.</li></ul><p>ISP is not about creating more interfaces.<br>It’s about creating <strong>the right interfaces</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c09a74c176b3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SOLID Principles Part 3: Why the Liskov Substitution Principle (LSP) Is Key to True Polymorphism]]></title>
            <link>https://medium.com/@theparthmaru/solid-principles-part-3-why-the-liskov-substitution-principle-lsp-is-key-to-true-polymorphism-81cbe6b195f5?source=rss-6dc55053f943------2</link>
            <guid isPermaLink="false">https://medium.com/p/81cbe6b195f5</guid>
            <category><![CDATA[solid-principles]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Parth Maru]]></dc:creator>
            <pubDate>Sat, 22 Nov 2025 19:44:12 GMT</pubDate>
            <atom:updated>2025-11-22T19:44:12.693Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Inheritance is one of the most powerful features in object-oriented programming — but it’s also one of the easiest to misuse.</p><p>Many systems start clean, but over time developers add subclasses that don’t fully behave like their parent class. This leads to broken polymorphism, unexpected exceptions, and code that becomes increasingly fragile with every new feature.</p><p>This is exactly what the <strong>Liskov Substitution Principle (LSP)</strong> aims to prevent.</p><p>LSP states:</p><blockquote>Objects of a superclass should be replaceable with objects of its subclasses without affecting the correctness of the program.</blockquote><p>In simpler words:</p><blockquote>Wherever you use a parent class, you should be able to use any of its subclasses without breaking behaviour.</blockquote><p>If that substitution breaks anything — even subtly — LSP has been violated.</p><h3>Example 1: The Credit Card Payment Problem</h3><p>Let’s explore a real-world scenario involving different credit card types.</p><p>❌ <strong>Bad Code — Violating LSP</strong></p><p><strong>CreditCard.java</strong></p><pre>public abstract class CreditCard {<br><br>    public abstract void tapAndPay();<br>    public abstract void onlineTransfer();<br>    public abstract void swipeAndPay();<br>    public abstract void mandatePayment();<br>    public abstract void upiPayment();<br>    public abstract void internationalPayment();<br>}</pre><p>Here’s the issue:</p><ul><li>Not all cards support <strong>UPI payments</strong></li><li>Not all cards support <strong>international payments</strong></li></ul><p>But subclasses are forced to implement everything — even when they cannot support certain operations.</p><p><strong>MasterCard.java</strong></p><pre>@Override<br>public void upiPayment() {<br>    throw new UnsupportedOperationException(&quot;UPI not supported&quot;);<br>}</pre><p><strong>RuPayCard.java</strong></p><pre>@Override<br>public void internationalPayment() {<br>    throw new UnsupportedOperationException(&quot;International not supported&quot;);<br>}</pre><p>This is a <strong>complete LSP violation</strong>. Why?</p><p>Because a subclass is <strong>breaking the behavioural contract</strong> defined by its parent.</p><h3>❗ What Does This Lead To?</h3><p>Bad client code like:</p><pre>if (card instanceof RuPayCard) {<br>    card.upiPayment();<br>}</pre><p>Once you start writing instanceof checks, your abstraction dies.</p><p>This is exactly what LSP is trying to protect you from.</p><h3>✅ Refactoring for LSP — A Better Approach</h3><p>We fix this by splitting behaviours into <strong>capability-based interfaces</strong>.</p><p>Not every card can do everything — so we don’t force them.</p><p><strong>Step 1: Keep the Base Class Minimal</strong></p><pre>public abstract class CreditCard {<br>    public abstract void tapAndPay();<br>    public abstract void onlineTransfer();<br>    public abstract void swipeAndPay();<br>    public abstract void mandatePayment();<br>}</pre><p>Only core, universal behaviours belong here.</p><p><strong>Step 2: Define Capability Interfaces</strong></p><pre>public interface UPICompatiblePaymentCreditCard {<br>    void upiPayment();<br>}</pre><pre>public interface InternationalCompatiblePaymentCreditCards {<br>    void internationalPayment();<br>}</pre><p>Each card now chooses capabilities based on what it truly supports.</p><p><strong>Step 3: Concrete Implementations</strong></p><p><strong>MasterCard.java</strong></p><pre>public class MasterCard extends CreditCard <br>        implements InternationalCompatiblePaymentCreditCards {<br><br>    @Override<br>    public void internationalPayment() {<br>        System.out.println(&quot;International payment via Mastercard&quot;);<br>    }<br>}</pre><p><strong>RuPayCard.java</strong></p><pre>public class RuPayCard extends CreditCard <br>        implements UPICompatiblePaymentCreditCard {<br><br>    @Override<br>    public void upiPayment() {<br>        System.out.println(&quot;UPI payment via RuPay&quot;);<br>    }<br>}</pre><p><strong>Step 4: Using the New Design</strong></p><pre>List&lt;UPICompatiblePaymentCreditCard&gt; upiCards = new ArrayList&lt;&gt;();<br><br>for (UPICompatiblePaymentCreditCard card : upiCards) {<br>    card.upiPayment();<br>}</pre><p>Every card in this list <strong>must</strong> support UPI — guaranteed by the interface.</p><p>No exceptions.<br> No weird hacks.<br> No instanceof.</p><p>LSP achieved. ✔️</p><h3>🔍 How to Detect an LSP Violation</h3><p>If any of these occur, you are breaking LSP:</p><h4>1. Subclasses throw unexpected exceptions</h4><p>(UnsupportedOperationException = 100% LSP violation)</p><h4>2. Subclasses have empty or do-nothing methods</h4><p>Indicates forced inheritance.</p><h4>3. You use instanceof or type-checking</h4><p>Means your abstraction isn’t abstract.</p><h4>4. Replacing a subclass breaks behaviour</h4><p>Even subtle changes (timing, state, constraints) count as violations.</p><h3>🧠 Why LSP Matters</h3><p>LSP isn’t just about inheritance.</p><p>It protects:</p><ul><li><strong>Polymorphism</strong></li><li><strong>Abstraction boundaries</strong></li><li><strong>Code stability</strong></li><li><strong>Extensibility</strong></li></ul><p>Violating LSP creates classes that lie about their capabilities.</p><p>Following LSP ensures subclasses always behave safely and predictably.</p><h3>⚙️ Design Patterns at Play</h3><p>LSP naturally encourages:</p><ul><li><strong>Interface segregation</strong></li><li><strong>Composition over inheritance</strong></li><li><strong>Capability-driven design</strong></li><li><strong>Clean polymorphic behaviour</strong></li></ul><p>These patterns lead to more stable and maintainable systems.</p><h3>🧩 Summary</h3><ul><li>Subclasses must honour the behaviours promised by their parent.</li><li>They must <strong>not</strong> throw exceptions for valid parent operations.</li><li>They must <strong>not</strong> require caller-side instanceof checks.</li><li>They must behave consistently wherever their parent is expected.</li></ul><p>If your subclass cannot support certain behaviours,<br>that behaviour doesn’t belong in the parent class.</p><h3>💬 Final Thoughts</h3><p>The Liskov Substitution Principle ensures that:</p><ul><li>Inheritance is meaningful</li><li>Polymorphism works correctly</li><li>Abstractions remain stable</li><li>Code doesn’t break when new subclasses are introduced</li></ul><p>You don’t follow LSP by accident — <br> you enforce it consciously through thoughtful design.</p><p>LSP is what makes your inheritance tree reliable and your system future-proof.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81cbe6b195f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SOLID Principles Part 2: How the Open/Closed Principle (OCP) Keeps Your Code Stable as It Grows]]></title>
            <link>https://medium.com/@theparthmaru/solid-principles-part-2-how-the-open-closed-principle-ocp-keeps-your-code-stable-as-it-grows-81efafcad54d?source=rss-6dc55053f943------2</link>
            <guid isPermaLink="false">https://medium.com/p/81efafcad54d</guid>
            <category><![CDATA[systems-thinking]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <dc:creator><![CDATA[Parth Maru]]></dc:creator>
            <pubDate>Fri, 31 Oct 2025 17:19:30 GMT</pubDate>
            <atom:updated>2025-10-31T17:19:30.507Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>As software evolves, one of the hardest challenges we face is <strong>adding new features without breaking existing code</strong>.</p><p>Every time we modify old, stable code, we risk introducing new bugs and destabilizing the system. This is where the <strong>Open/Closed Principle (OCP)</strong> in the SOLID family comes to the rescue.</p><blockquote><strong><em>The Open/Closed Principle states:</em></strong><em><br> </em>Software entities (classes, modules, functions) should be open for extension but closed for modification.</blockquote><p>In simpler terms:</p><blockquote><em>You should be able to add new behaviour without changing existing, tested code.</em></blockquote><h3>Example 1: Payment Processing System</h3><p>Let’s explore a classic scenario — <strong>payment processing</strong>.</p><h3>❌ Bad Code — Violating OCP</h3><p>PaymentType.java</p><pre>public enum PaymentType {<br>    CREDIT_CARD,<br>    BANK_TRANSFER,<br>    PAYPAL<br>}</pre><p>PaymentProcessor.java</p><pre>public class PaymentProcessor {<br>    public void processPayment(PaymentType paymentType, double amount) {<br>        switch (paymentType) {<br>            case CREDIT_CARD:<br>                System.out.println(&quot;Process payment through CREDIT CARD&quot;);<br>                break;<br><br>            case BANK_TRANSFER:<br>                System.out.println(&quot;Process payment through BANK TRANSFER&quot;);<br>                break;<br><br>            case PAYPAL:<br>                System.out.println(&quot;Process payment through PAYPAL&quot;);<br>                break;<br><br>            default:<br>                System.out.println(&quot;Invalid payment type&quot;);<br>                break;<br>        }<br>    }<br>}</pre><p>At first glance, this seems fine but let’s say the business wants to add <strong>Crypto payments</strong>.</p><p>To support this:</p><ol><li>You’d have to add a new enum: CRYPTO.</li><li>You’d also have to modify the switch statement.</li></ol><p>This violates OCP. We’re <em>modifying</em> existing code rather than <em>extending</em> it.<br>That’s how new bugs sneak in.</p><h3>✅ Refactoring for OCP — A Better Approach</h3><p>We can fix this design using <strong>interfaces, polymorphism, and a registry pattern</strong>.</p><h4>Step 1: Create a PaymentProcessor Interface</h4><pre>public interface PaymentProcessor {<br>    PaymentType supports();<br>    void processPayment();<br>}</pre><p>This defines the contract where each payment type will implement its own processor.</p><h4>Step 2: Concrete Implementations</h4><p>BankTransferProcessor.java</p><pre>public class BankTransferProcessor implements PaymentProcessor {<br>    @Override<br>    public PaymentType supports() {<br>        return PaymentType.BANK_TRANSFER;<br>    }<br><br>    @Override<br>    public void processPayment() {<br>        // Logic to process bank transfer payments<br>    }<br>}</pre><p>CreditCardProcessor.java</p><pre>public class CreditCardProcessor implements PaymentProcessor {<br>    @Override<br>    public PaymentType supports() {<br>        return PaymentType.CREDIT_CARD;<br>    }<br><br>    @Override<br>    public void processPayment() {<br>        // Logic to process credit card payments<br>    }<br>}</pre><p>PaypalProcessor.java</p><pre>public class PaypalProcessor implements PaymentProcessor {<br>    @Override<br>    public PaymentType supports() {<br>        return PaymentType.PAYPAL;<br>    }<br><br>    @Override<br>    public void processPayment() {<br>        // Logic to process PayPal payments<br>    }<br>}</pre><h4>Step 3: The PaymentProcessorRegistry</h4><pre>import java.util.HashMap;<br>import java.util.Map;<br><br>public class PaymentProcessorRegistry {<br>    private final Map&lt;PaymentType, PaymentProcessor&gt; processors = new HashMap&lt;&gt;();<br><br>    public PaymentProcessorRegistry() {<br>        processors.put(PaymentType.CREDIT_CARD, new CreditCardProcessor());<br>        processors.put(PaymentType.BANK_TRANSFER, new BankTransferProcessor());<br>        processors.put(PaymentType.PAYPAL, new PaypalProcessor());<br>    }<br><br>    public PaymentProcessor getPaymentProcessor(PaymentType type) {<br>        return processors.get(type);<br>    }<br>}</pre><p>The registry is a <strong>lookup map</strong> that connects each payment type to its processor <strong>no switch statements</strong> needed.</p><h4>Step 4: Using the Registry</h4><pre>public class Main {<br>    public static void main(String[] args) {<br>        PaymentProcessorRegistry registry = new PaymentProcessorRegistry();<br><br>        PaymentProcessor paypal = registry.getPaymentProcessor(PaymentType.PAYPAL);<br>        paypal.processPayment();<br><br>        PaymentProcessor creditCard = registry.getPaymentProcessor(PaymentType.CREDIT_CARD);<br>        creditCard.processPayment();<br>    }<br>}</pre><p>Want to add <strong>Crypto payments</strong> now?<br> Simply:</p><ol><li>Add CRYPTO to the PaymentType enum.</li><li>Create a CryptoProcessor implementing PaymentProcessor.</li><li>Register it in the registry.</li></ol><p>No need to touch old, tested code ✅</p><h3>🔍 How to Detect an OCP Violation</h3><ul><li>If adding a new feature <strong>requires modifying existing classes</strong>, OCP is being violated.</li><li>If you can add a new feature by <strong>creating new classes</strong> (without editing old ones), you’re following OCP correctly.</li></ul><h3>🧠 Why a Map Beats a Switch Case</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*uClHH05ToCU6czQnFua-mA.png" /></figure><p>Instead of asking “If it’s X, do Y,” we simply <strong>look up behaviour</strong> in a registry. The code knows what to do.</p><h3>⚙️ Design Patterns at Play</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*_7wAr8R-AT5Fs915k7CQXw.png" /></figure><h3>🧭 When Enums Are Good or Bad</h3><ul><li>✅ <strong>Good:</strong> Used as identifiers or keys (like PaymentType)</li><li>❌ <strong>Bad:</strong> Used to control logic flow in switch statements</li></ul><p>Enums themselves aren’t evil — misuse is.</p><h3>🧩 Summary</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*eI1uquvnlHQ-eifHpYMl7g.png" /></figure><h3>💬 Final Thoughts</h3><ul><li>The <strong>Open/Closed Principle</strong> is not about avoiding enums or switches entirely.</li><li>It’s about designing systems that <strong>grow gracefully</strong>.</li><li>Every time you extend a system without touching existing, stable code — <br> you’re applying OCP.</li><li>Design for growth, not just for today’s requirements.</li><li>That’s how maintainable systems are built.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81efafcad54d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SOLID Principles Part 1: Why Single Responsibility (SRP) Makes Your Code Future-Proof]]></title>
            <link>https://medium.com/@theparthmaru/solid-principles-part-1-why-single-responsibility-srp-makes-your-code-future-proof-7d137dadb776?source=rss-6dc55053f943------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d137dadb776</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[solid-principles]]></category>
            <dc:creator><![CDATA[Parth Maru]]></dc:creator>
            <pubDate>Sat, 25 Oct 2025 20:16:37 GMT</pubDate>
            <atom:updated>2025-10-25T20:16:37.150Z</atom:updated>
            <content:encoded><![CDATA[<p>When we start building applications, we often put everything related to an object inside a single class: data, logic, printing, storage, reporting, and more. It feels convenient at first until requirements change.</p><p>That’s when we realize the moment one small feature needs modification, the entire class falls apart.<br>This is exactly what the <strong>Single Responsibility Principle (SRP)</strong> helps us avoid.</p><h3>What is SRP?</h3><blockquote>“A class should have one, and only one, reason to change.”<br>- Robert C. Martin (Uncle Bob)</blockquote><p>SRP applies not only to classes, but also to:<br>1. Methods / Functions<br>2. Modules<br>3. Services</p><p>Here, <strong>responsibility</strong> means <strong>the reason to change code</strong> and not necessarily <strong>“one tiny task.”</strong><br>A class may perform multiple tasks as long as they all support one clear purpose.</p><h3>What does SRP try to prevent?</h3><p>When one class handles unrelated responsibilities, the risk multiplies:</p><ul><li>Business logic changes? → Modify the class</li><li>Output format changes? → Modify the class</li><li>Validation rules change? → Modify the class</li></ul><p>The class becomes fragile, highly coupled, and hard to test.</p><h3>Signs Your Class Violates SRP</h3><ol><li>You can’t describe what the class does in a single sentence without using “and”</li><li>The class name becomes vague: Helper, Manager, Processor, etc.</li><li>Too many reasons for different people to modify the same file.</li><li>Unit testing requires complex setup because “too much is happening”.</li></ol><p>If multiple intentions coexist in a class → SRP is broken.</p><h3>Bad Example: One Class Doing Too Much</h3><pre>public class Employee {<br><br>    private int id;<br><br>    public Employee(int id) {<br>        this.id = id;<br>    }<br><br>    public int getId() {<br>        return this.id;<br>    }<br><br>    public String fetchBioData() {<br>        return &quot;Some bio data&quot;;<br>    }<br><br>    public double calculateSalary() {<br>        double salary;<br>        // Logic to calculate the salary<br>        return salary;<br>    }<br><br>    public void printPerformanceData() {<br>        // Logic to display the performance data<br>        System.out.println(&quot;Performance data...&quot;);<br>    }<br>}</pre><h3>Why does this violate SRP?</h3><p>This class has multiple independent responsibilities:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*nd-skTFP41obsDCC7KcYgA.png" /></figure><p>More changes → higher chance of regression → code becomes unstable.</p><p>And testing?<br>You must mock salary logic + bio fetch + performance printing — all in one test.</p><h3>Fixing the Employee Class</h3><p>We <strong>separate reasons to change</strong> into their own components:</p><pre>public class Employee {<br>    private int id;<br>    public Employee(int id) { this.id = id; }<br>    public int getId() { return this.id; }<br>}</pre><blockquote>Now <strong><em>Employee</em></strong> manages only identity &amp; entity state.</blockquote><p>Other responsibilities move into independent classes:</p><pre>public class EmployeeSalaryCalculator {<br>    public double calculateSalary(Employee employee) {<br>        double salary;<br>        <br>        // Business logic to calculate the salary<br>        <br>        return salary;<br>    }<br>}</pre><blockquote>Only salary rule changes affect this class.</blockquote><pre>public class FetchEmployeeBioData {<br>    public void fetchData(Employee employee) {<br>        // Logic to fetch and print the data<br>    }<br>}</pre><blockquote>Only data format or structure changes affect this class.</blockquote><pre>public class EmployeePerformanceEvaluator {<br>    public void evaluatePerformance(Employee employee) {<br>        // Evaluation logic<br>    }<br>}</pre><blockquote>Only performance logic changes affect this class.</blockquote><h3>What We Gained?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*1_BB0imszQZULD1AqkpDUQ.png" /></figure><p>This leads to:</p><ol><li>Better maintainability</li><li>Clear ownership</li><li>Easy extension</li><li>Increased re-usability</li></ol><h3>Why SRP Matters in Real Projects</h3><ul><li>Software changes constantly that’s the only guarantee.</li><li>SRP helps ensure change affects the smallest possible part of the codebase.</li><li>It also sets a strong foundation for the rest of the SOLID principles like:</li></ul><ol><li>OCP → Extend behavior without modifying existing code.</li><li>DIP → Reduce concrete dependencies.</li></ol><p><em>If you master SRP, you’re already writing cleaner object-oriented code than most developers.</em></p><h3>Conclusion</h3><p>SRP isn’t about counting methods, it’s about clarity of purpose.</p><p>Ask yourself:</p><blockquote>“Will different reasons force different stakeholders to change this class?”</blockquote><p>If yes → it’s time to split responsibilities.</p><h4>What’s your experience with refactoring SRP violations?</h4><p><em>Share your examples or challenges — I’d love to discuss them!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d137dadb776" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SOLID Principles — The Foundation of Clean and Scalable Software]]></title>
            <link>https://medium.com/@theparthmaru/solid-principles-the-foundation-of-clean-and-scalable-software-818d4b6e2207?source=rss-6dc55053f943------2</link>
            <guid isPermaLink="false">https://medium.com/p/818d4b6e2207</guid>
            <category><![CDATA[solid-principles-in-java]]></category>
            <category><![CDATA[solid-principles]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Parth Maru]]></dc:creator>
            <pubDate>Thu, 23 Oct 2025 13:14:30 GMT</pubDate>
            <atom:updated>2025-10-23T13:14:54.102Z</atom:updated>
            <content:encoded><![CDATA[<h3>SOLID Principles — The Foundation of Clean and Scalable Software</h3><blockquote>Why every developer should master SOLID to write maintainable, extensible, and high-quality code.</blockquote><p>Software development isn’t just about writing code that works. It is about writing code that <strong>continues to work</strong>, even as requirements evolve, features expand, and teams grow. If you have ever revisited your own code after a few months and thought, <em>“Wow… who wrote this mess?”, </em>you’re not alone.</p><p>As we progress in our careers, we begin to realize that clean architecture and maintainability matter just as much as functionality. That’s where the <strong>SOLID Principles</strong> step in.</p><p>SOLID is a set of five <strong>object-oriented design</strong> principles formulated by Robert C. Martin (Uncle Bob). These principles have become essential guidelines for writing software that is:</p><ol><li>Easy to maintain.</li><li>Flexible to change.</li><li>Scalable as features grow.</li><li>Testable and modular.</li><li>Aligned with real-world business needs.</li></ol><h3>What does SOLID stand for?</h3><p>SOLID is an acronym representing five foundational design principles:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*EJoKa2Pxf3nhBrIp0vaL7A.png" /></figure><p>Together, these principles help reduce code smells like:</p><ul><li>Tight coupling</li><li>Fragile and buggy enhancements</li><li>Monster classes doing too much</li><li>Difficult-to-test components</li><li>Repeated code across modules</li></ul><p>SOLID enables a design mindset where software evolves <strong>without breaking what already works</strong>.</p><h3>Why am I writing this series?</h3><p>Over the past few weeks, I’ve been deeply studying SOLID while applying these principles to real-life problems. The more I learned, the more clarity I gained in writing cleaner and smarter code. So I decided:</p><blockquote><em>Why not share the journey and help others learn along the way?</em></blockquote><p>This series will break down each principle with:</p><ul><li>Detailed explanations.</li><li>Practical, real-world examples (No Animals or Cars!).</li><li>Bad vs. Improved code comparisons.</li><li>Common misconceptions.</li><li>How to identify violations in existing code.</li></ul><p>My goal is to help both beginners and working developers build a strong foundation in software design.</p><h3>Who is this series for?</h3><p>If you are:</p><ul><li>A beginner learning Object-Oriented Programming.</li><li>Preparing for software engineering interviews.</li><li>A developer trying to write clean and scalable code.</li><li>Someone who looks at old code and regrets their past decisions.</li></ul><p>…then this series is for you.</p><h3>What’s coming next?</h3><p>Up next in this series:</p><h4>Part 1: Single Responsibility Principle (SRP)</h4><p>Why “one reason to change” can save hours of debugging and refactoring.</p><p><strong>Let’s become better engineers — one principle at a time.</strong></p><p>If you’d like to follow along, click <strong>Follow</strong> on Medium and connect with me on LinkedIn for updates. Share your thoughts, feedback, and your own experiences with SOLID. I would love to hear them!</p><h3>Stay connected</h3><p>Follow me on Medium for the full series: <a href="https://medium.com/@theparthmaru">@theparthmaru</a><br>Connect with me on LinkedIn: <a href="https://www.linkedin.com/in/theparthmaru/">@theparthmaru</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=818d4b6e2207" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>