<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Saras Growth Space</title>
    <description>The latest articles on DEV Community by Saras Growth Space (@saras_growth_space).</description>
    <link>https://dev.to/saras_growth_space</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3805711%2F9d71d829-9e4b-42ad-919e-ef864f55f79d.png</url>
      <title>DEV Community: Saras Growth Space</title>
      <link>https://dev.to/saras_growth_space</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/saras_growth_space"/>
    <language>en</language>
    <item>
      <title>LLD Object-Oriented Design: Dependency Injection (Decoupling System Design)</title>
      <dc:creator>Saras Growth Space</dc:creator>
      <pubDate>Tue, 26 May 2026 15:00:00 +0000</pubDate>
      <link>https://dev.to/saras_growth_space/lld-object-oriented-design-dependency-injection-decoupling-system-design-5d0n</link>
      <guid>https://dev.to/saras_growth_space/lld-object-oriented-design-dependency-injection-decoupling-system-design-5d0n</guid>
      <description>&lt;p&gt;After defining contracts using interfaces and abstract classes, the next problem appears naturally in real systems:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;How do we connect all these components without tightly coupling them?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is where Dependency Injection (DI) becomes essential.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Problem Without Dependency Injection
&lt;/h2&gt;

&lt;p&gt;When a class creates its own dependencies, it becomes tightly coupled.&lt;/p&gt;




&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;OrderService&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;payment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;CardPayment&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  What’s wrong here?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;OrderService depends on a specific implementation&lt;/li&gt;
&lt;li&gt;You cannot easily switch payment methods&lt;/li&gt;
&lt;li&gt;Testing becomes difficult&lt;/li&gt;
&lt;li&gt;Changes in one class affect others&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This creates rigid systems.&lt;/p&gt;




&lt;h2&gt;
  
  
  What is Dependency Injection?
&lt;/h2&gt;

&lt;p&gt;Dependency Injection means:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Providing dependencies from the outside instead of creating them inside the class.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Correct Design
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;OrderService&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payment&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;payment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;payment&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the dependency is &lt;strong&gt;injected externally&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  Usage
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;service&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;OrderService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;CardPayment&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;service&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;OrderService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;UpiPayment&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  What Changed?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;OrderService no longer decides what payment system to use&lt;/li&gt;
&lt;li&gt;responsibility is moved outside&lt;/li&gt;
&lt;li&gt;system becomes flexible&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Why Dependency Injection Matters
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Loose Coupling
&lt;/h3&gt;

&lt;p&gt;Classes do not depend on concrete implementations.&lt;/p&gt;




&lt;h3&gt;
  
  
  2. Easy Testing
&lt;/h3&gt;

&lt;p&gt;Mock objects can replace real dependencies.&lt;/p&gt;




&lt;h3&gt;
  
  
  3. Flexibility
&lt;/h3&gt;

&lt;p&gt;You can change behavior without modifying core logic.&lt;/p&gt;




&lt;h2&gt;
  
  
  Real System Example
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Notification System
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;NotificationService&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;notifier&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;notifier&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;notifier&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;notifier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now different implementations can be injected:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;EmailNotifier&lt;/li&gt;
&lt;li&gt;SmsNotifier&lt;/li&gt;
&lt;li&gt;PushNotifier&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Key Design Insight
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Classes should focus on what they do, not what they depend on.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Dependency Injection vs Object Creation
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Without DI&lt;/th&gt;
&lt;th&gt;With DI&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;class creates dependencies&lt;/td&gt;
&lt;td&gt;dependencies passed externally&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;tight coupling&lt;/td&gt;
&lt;td&gt;loose coupling&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;hard to test&lt;/td&gt;
&lt;td&gt;easy to test&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;rigid design&lt;/td&gt;
&lt;td&gt;flexible design&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Where Object Creation Should Happen
&lt;/h2&gt;

&lt;p&gt;If classes don’t create dependencies, then who does?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Caller&lt;/li&gt;
&lt;li&gt;Factory&lt;/li&gt;
&lt;li&gt;Composition Root (central setup layer)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This separation is critical for clean architecture.&lt;/p&gt;




&lt;h2&gt;
  
  
  Common Mistake
&lt;/h2&gt;

&lt;p&gt;Beginners often:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;mix creation logic inside business classes&lt;/li&gt;
&lt;li&gt;overuse DI without structure&lt;/li&gt;
&lt;li&gt;confuse DI with factories&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Important Clarification
&lt;/h2&gt;

&lt;p&gt;Dependency Injection is NOT:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a framework&lt;/li&gt;
&lt;li&gt;a design pattern for creation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is a &lt;strong&gt;design principle for decoupling&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Design Principle
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Depend on abstractions, not concrete implementations — and receive dependencies instead of creating them.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Real-World Analogy
&lt;/h2&gt;

&lt;p&gt;Think of a mobile phone:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;it does not create a SIM card internally&lt;/li&gt;
&lt;li&gt;SIM is inserted externally&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The phone works regardless of SIM provider.&lt;/p&gt;




&lt;h2&gt;
  
  
  One-Line Takeaway
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Dependency Injection decouples system components by moving responsibility of object creation outside the class.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>lld</category>
      <category>systemdesign</category>
      <category>softwareengineering</category>
      <category>codinginterview</category>
    </item>
    <item>
      <title>LLD Object-Oriented Design: Interfaces &amp; Abstract Classes (Designing Contracts)</title>
      <dc:creator>Saras Growth Space</dc:creator>
      <pubDate>Mon, 25 May 2026 15:00:00 +0000</pubDate>
      <link>https://dev.to/saras_growth_space/lld-object-oriented-design-interfaces-abstract-classes-designing-contracts-138f</link>
      <guid>https://dev.to/saras_growth_space/lld-object-oriented-design-interfaces-abstract-classes-designing-contracts-138f</guid>
      <description>&lt;p&gt;After understanding composition, inheritance, and polymorphism, the next important step is learning how to define &lt;strong&gt;clear behavioral contracts&lt;/strong&gt; between components.&lt;/p&gt;

&lt;p&gt;This is where interfaces and abstract classes become essential.&lt;/p&gt;

&lt;p&gt;They help answer one of the most important questions in system design:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“What should this component be capable of doing?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;without tightly coupling the system to a specific implementation.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Contracts Matter in System Design
&lt;/h2&gt;

&lt;p&gt;In real systems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;multiple implementations exist&lt;/li&gt;
&lt;li&gt;components evolve independently&lt;/li&gt;
&lt;li&gt;implementations may change over time&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If systems depend directly on concrete classes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;flexibility decreases&lt;/li&gt;
&lt;li&gt;testing becomes difficult&lt;/li&gt;
&lt;li&gt;coupling increases&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Contracts solve this problem.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;What is an Interface?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;An interface defines:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A capability contract that implementing classes must follow.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It specifies:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;what operations are available&lt;/li&gt;
&lt;li&gt;not how they are implemented&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Payment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;pay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;pass&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Any implementation must provide:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;pay()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But implementation details remain independent.&lt;/p&gt;




&lt;h2&gt;
  
  
  Core Idea
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Interfaces define capability expectations, not implementation details.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;What is an Abstract Class?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;An abstract class provides:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Partial implementation along with abstract behavior contracts.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It is useful when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;some logic is common across implementations&lt;/li&gt;
&lt;li&gt;some behavior varies by subclass&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Notification&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Logging notification&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;pass&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;log()&lt;/code&gt; → shared behavior&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;send()&lt;/code&gt; → implementation-specific behavior&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Interface vs Abstract Class
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Interface&lt;/th&gt;
&lt;th&gt;Abstract Class&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;defines contract&lt;/td&gt;
&lt;td&gt;defines partial behavior&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;focuses on capability&lt;/td&gt;
&lt;td&gt;focuses on shared structure&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;minimal implementation&lt;/td&gt;
&lt;td&gt;can contain implementation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;enables loose coupling&lt;/td&gt;
&lt;td&gt;enables reuse + extension&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Key Mental Model
&lt;/h2&gt;

&lt;p&gt;Think of it this way:&lt;/p&gt;

&lt;h3&gt;
  
  
  Interface
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;“What can this object do?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Abstract Class
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;“What common behavior already exists?”&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Real System Example
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Payment System&lt;/strong&gt;
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Contract
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Payment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;pay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;pass&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Implementations
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CardPayment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Payment&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;pay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Processing card payment&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UpiPayment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Payment&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;pay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Processing UPI payment&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Usage
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;process&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Payment&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;payment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pay&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the system depends on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;abstraction
not:&lt;/li&gt;
&lt;li&gt;concrete implementation&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Why Interfaces Matter in LLD
&lt;/h2&gt;

&lt;p&gt;Interfaces help achieve:&lt;/p&gt;




&lt;h3&gt;
  
  
  1. Loose Coupling
&lt;/h3&gt;

&lt;p&gt;Components communicate through contracts instead of implementations.&lt;/p&gt;




&lt;h3&gt;
  
  
  2. Extensibility
&lt;/h3&gt;

&lt;p&gt;New implementations can be added safely.&lt;/p&gt;




&lt;h3&gt;
  
  
  3. Testability
&lt;/h3&gt;

&lt;p&gt;Mock implementations become easy.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;MockPayment&lt;/li&gt;
&lt;li&gt;FakeNotificationService&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  4. System Scalability
&lt;/h3&gt;

&lt;p&gt;Independent teams can build implementations separately while following the same contract.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Abstract Classes Matter
&lt;/h2&gt;

&lt;p&gt;Abstract classes help when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;logic is partially shared&lt;/li&gt;
&lt;li&gt;duplication needs reduction&lt;/li&gt;
&lt;li&gt;related classes have common behavior&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;They provide:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;controlled reuse&lt;/li&gt;
&lt;li&gt;shared structure&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Common Mistake
&lt;/h2&gt;

&lt;p&gt;Beginners often:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;create interfaces for everything&lt;/li&gt;
&lt;li&gt;or avoid abstractions entirely&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both create problems.&lt;/p&gt;




&lt;h3&gt;
  
  
  Over-Abstraction
&lt;/h3&gt;

&lt;p&gt;Too many unnecessary interfaces lead to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;complexity&lt;/li&gt;
&lt;li&gt;indirection&lt;/li&gt;
&lt;li&gt;unreadable systems&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Under-Abstraction
&lt;/h3&gt;

&lt;p&gt;No contracts lead to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;tight coupling&lt;/li&gt;
&lt;li&gt;rigid systems&lt;/li&gt;
&lt;li&gt;difficult testing&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Design Principle
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Depend on abstractions for flexibility, but introduce abstractions only when variation or decoupling is actually needed.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Real-World Analogy
&lt;/h2&gt;

&lt;p&gt;Think of a charging socket.&lt;/p&gt;

&lt;p&gt;The socket defines:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;voltage standard&lt;/li&gt;
&lt;li&gt;connection contract&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Different chargers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Apple&lt;/li&gt;
&lt;li&gt;Samsung&lt;/li&gt;
&lt;li&gt;Laptop adapters&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;all work because they follow the same contract.&lt;/p&gt;

&lt;p&gt;The socket does not care about internal implementation.&lt;/p&gt;




&lt;h2&gt;
  
  
  One-Line Takeaway
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Interfaces define what a component must be capable of doing, while abstract classes help share common behavior across related implementations.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>lld</category>
      <category>systemdesign</category>
      <category>softwareengineering</category>
      <category>codinginterview</category>
    </item>
    <item>
      <title>LLD Object-Oriented Design: Composition vs Inheritance (Choosing the Right Relationship)</title>
      <dc:creator>Saras Growth Space</dc:creator>
      <pubDate>Sun, 24 May 2026 15:00:00 +0000</pubDate>
      <link>https://dev.to/saras_growth_space/lld-object-oriented-design-composition-vs-inheritance-choosing-the-right-relationship-34pl</link>
      <guid>https://dev.to/saras_growth_space/lld-object-oriented-design-composition-vs-inheritance-choosing-the-right-relationship-34pl</guid>
      <description>&lt;p&gt;After learning inheritance and polymorphism, the next critical design decision is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;How should objects be connected to each other?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There are two primary ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inheritance (is-a relationship)&lt;/li&gt;
&lt;li&gt;Composition (has-a relationship)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Understanding when to use which is one of the most important skills in LLD.&lt;/p&gt;




&lt;h2&gt;
  
  
  Inheritance Recap (is-a)
&lt;/h2&gt;

&lt;p&gt;Inheritance means:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A child class is a specialized version of a parent class.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dog is an Animal&lt;/li&gt;
&lt;li&gt;Car is a Vehicle&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It creates a hierarchical relationship.&lt;/p&gt;




&lt;h2&gt;
  
  
  Composition (has-a Relationship)
&lt;/h2&gt;

&lt;p&gt;Composition means:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;An object is made up of other objects.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Instead of inheriting behavior, you &lt;strong&gt;delegate it to another object&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Engine&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Engine started&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;engine&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;engine&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;engine&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;engine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Car HAS an Engine&lt;/li&gt;
&lt;li&gt;behavior is delegated, not inherited&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Key Difference
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Inheritance&lt;/th&gt;
&lt;th&gt;Composition&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;is-a relationship&lt;/td&gt;
&lt;td&gt;has-a relationship&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;tight coupling&lt;/td&gt;
&lt;td&gt;loose coupling&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;rigid hierarchy&lt;/td&gt;
&lt;td&gt;flexible design&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;behavior inherited&lt;/td&gt;
&lt;td&gt;behavior delegated&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Why Composition is Preferred in LLD
&lt;/h2&gt;

&lt;p&gt;In real systems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;requirements change frequently&lt;/li&gt;
&lt;li&gt;behavior varies across contexts&lt;/li&gt;
&lt;li&gt;rigid hierarchies break easily&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Composition provides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;flexibility&lt;/li&gt;
&lt;li&gt;reusability&lt;/li&gt;
&lt;li&gt;easier maintenance&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Problem with Overusing Inheritance
&lt;/h2&gt;

&lt;p&gt;Inheritance can lead to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;deep class hierarchies&lt;/li&gt;
&lt;li&gt;fragile base classes&lt;/li&gt;
&lt;li&gt;unexpected side effects&lt;/li&gt;
&lt;li&gt;tightly coupled systems&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As systems grow:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;inheritance becomes difficult to manage&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Composition Enables Flexibility
&lt;/h2&gt;

&lt;p&gt;With composition, behavior can be changed dynamically.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Engine&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Generic engine start&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ElectricEngine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Engine&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Electric engine start&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now Car can use any engine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;car&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ElectricEngine&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Core Design Insight
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Composition allows behavior to be plugged in, while inheritance locks behavior into a hierarchy.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Real-World Analogy
&lt;/h2&gt;

&lt;p&gt;Think of a car:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Car does NOT become an engine&lt;/li&gt;
&lt;li&gt;Car simply uses an engine&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Similarly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;objects should use components, not become them&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  When to Use Inheritance
&lt;/h2&gt;

&lt;p&gt;Use inheritance when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;clear is-a relationship exists&lt;/li&gt;
&lt;li&gt;behavior is stable&lt;/li&gt;
&lt;li&gt;substitution is valid&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Payment methods&lt;/li&gt;
&lt;li&gt;Base models&lt;/li&gt;
&lt;li&gt;Shared contracts&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  When to Use Composition
&lt;/h2&gt;

&lt;p&gt;Use composition when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;behavior can change&lt;/li&gt;
&lt;li&gt;multiple variations exist&lt;/li&gt;
&lt;li&gt;flexibility is required&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;notification systems&lt;/li&gt;
&lt;li&gt;payment processing pipelines&lt;/li&gt;
&lt;li&gt;service integrations&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Common Mistake
&lt;/h2&gt;

&lt;p&gt;Beginners often:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;force inheritance for reuse&lt;/li&gt;
&lt;li&gt;create unnecessary hierarchies&lt;/li&gt;
&lt;li&gt;mix unrelated behaviors into base classes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This leads to:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;rigid and fragile systems&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Design Principle
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Prefer composition over inheritance for flexible and maintainable systems.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  One-Line Takeaway
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Inheritance defines hierarchy, but composition defines flexibility through collaboration.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>lld</category>
      <category>systemdesign</category>
      <category>codinginterview</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>LLD Object-Oriented Design: Polymorphism (Design Without if-else)</title>
      <dc:creator>Saras Growth Space</dc:creator>
      <pubDate>Sat, 23 May 2026 15:00:00 +0000</pubDate>
      <link>https://dev.to/saras_growth_space/lld-object-oriented-design-polymorphism-design-without-if-else-456m</link>
      <guid>https://dev.to/saras_growth_space/lld-object-oriented-design-polymorphism-design-without-if-else-456m</guid>
      <description>&lt;p&gt;After understanding inheritance, the next step is learning how systems can support multiple behaviors &lt;strong&gt;without constantly changing existing code&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This is where polymorphism becomes important.&lt;/p&gt;




&lt;h2&gt;
  
  
  What is Polymorphism?
&lt;/h2&gt;

&lt;p&gt;Polymorphism means:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The same operation can behave differently depending on the object handling it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In simple terms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;one common contract&lt;/li&gt;
&lt;li&gt;multiple implementations&lt;/li&gt;
&lt;li&gt;behavior selected at runtime&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Why Polymorphism Exists
&lt;/h2&gt;

&lt;p&gt;In real systems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;similar operations exist across different entities&lt;/li&gt;
&lt;li&gt;behavior changes based on type or implementation&lt;/li&gt;
&lt;li&gt;systems need extensibility without modification&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Without polymorphism, systems usually rely on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;large if-else chains&lt;/li&gt;
&lt;li&gt;switch-case logic&lt;/li&gt;
&lt;li&gt;type checking everywhere&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As systems grow, this becomes difficult to maintain.&lt;/p&gt;




&lt;h2&gt;
  
  
  Bad Design: Behavior Controlled Using if-else
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PaymentService&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;pay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payment_type&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;payment_type&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;card&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Card payment&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;payment_type&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;upi&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;UPI payment&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Problems with This Approach
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Every new type requires modification
&lt;/h3&gt;

&lt;p&gt;Adding WalletPayment means editing existing code.&lt;/p&gt;




&lt;h3&gt;
  
  
  2. Logic keeps growing
&lt;/h3&gt;

&lt;p&gt;The service becomes bloated over time.&lt;/p&gt;




&lt;h3&gt;
  
  
  3. Violates Open-Closed Principle
&lt;/h3&gt;

&lt;p&gt;The class is not closed for modification.&lt;/p&gt;




&lt;h3&gt;
  
  
  4. Behavior is centralized incorrectly
&lt;/h3&gt;

&lt;p&gt;Service decides behavior instead of objects themselves.&lt;/p&gt;




&lt;h2&gt;
  
  
  Better Design: Using Polymorphism
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Payment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;pay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;pass&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CardPayment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Payment&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;pay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Card payment&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UpiPayment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Payment&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;pay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;UPI payment&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Usage
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;process&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Payment&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;payment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pay&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the caller does not care:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;whether it is card payment&lt;/li&gt;
&lt;li&gt;UPI payment&lt;/li&gt;
&lt;li&gt;wallet payment&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The object itself decides behavior.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Actually Changed?
&lt;/h2&gt;

&lt;p&gt;Instead of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;service controlling behavior using conditions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;behavior is delegated to the object&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is the essence of polymorphism.&lt;/p&gt;




&lt;h2&gt;
  
  
  Key Idea: Same Message, Different Behavior
&lt;/h2&gt;

&lt;p&gt;The same method call:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pay()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;can produce different behavior depending on object type:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CardPayment → card processing&lt;/li&gt;
&lt;li&gt;UpiPayment → UPI processing&lt;/li&gt;
&lt;li&gt;WalletPayment → wallet processing&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Runtime Polymorphism
&lt;/h2&gt;

&lt;p&gt;This behavior selection happens during runtime.&lt;/p&gt;

&lt;p&gt;The system works with a common abstraction:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Payment&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But actual execution depends on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;underlying implementation object&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Important Clarification
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Polymorphism is not limited to inheritance alone.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It can also be achieved through:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;interfaces&lt;/li&gt;
&lt;li&gt;abstract classes&lt;/li&gt;
&lt;li&gt;shared contracts&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The core idea is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;multiple implementations behind a common abstraction&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Real System Example
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Notification System
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Notification&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;pass&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;EmailNotification&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Notification&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Email sent&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SmsNotification&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Notification&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;SMS sent&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Generic Usage
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;notification&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Notification&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;notification&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The calling code remains unchanged even when new notification types are added.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Polymorphism is Powerful
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Extensibility
&lt;/h3&gt;

&lt;p&gt;New behavior can be added without modifying existing logic.&lt;/p&gt;




&lt;h3&gt;
  
  
  2. Cleaner Systems
&lt;/h3&gt;

&lt;p&gt;Removes large conditional chains.&lt;/p&gt;




&lt;h3&gt;
  
  
  3. Better Separation of Concerns
&lt;/h3&gt;

&lt;p&gt;Each class owns its own behavior.&lt;/p&gt;




&lt;h3&gt;
  
  
  4. Improved Maintainability
&lt;/h3&gt;

&lt;p&gt;Changes remain isolated to specific implementations.&lt;/p&gt;




&lt;h2&gt;
  
  
  Polymorphism vs if-else
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;if-else approach&lt;/th&gt;
&lt;th&gt;Polymorphism approach&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;centralized conditions&lt;/td&gt;
&lt;td&gt;distributed behavior&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;difficult to extend&lt;/td&gt;
&lt;td&gt;easy to extend&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;service controls behavior&lt;/td&gt;
&lt;td&gt;objects control behavior&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;violates OCP&lt;/td&gt;
&lt;td&gt;follows OCP&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Common Mistake
&lt;/h2&gt;

&lt;p&gt;Beginners sometimes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;use polymorphism but still keep if-else checks&lt;/li&gt;
&lt;li&gt;create unnecessary type validations&lt;/li&gt;
&lt;li&gt;tightly couple services to implementations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This defeats the purpose of polymorphism.&lt;/p&gt;




&lt;h2&gt;
  
  
  Design Principle
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Behavior should live inside the object responsible for it, not inside a centralized conditional block.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  When to Use Polymorphism
&lt;/h2&gt;

&lt;p&gt;Use polymorphism when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;multiple implementations exist for same behavior&lt;/li&gt;
&lt;li&gt;behavior varies by type&lt;/li&gt;
&lt;li&gt;extensibility is important&lt;/li&gt;
&lt;li&gt;new variations are expected in future&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  One-Line Takeaway
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Polymorphism allows systems to support multiple behaviors through a common abstraction without modifying existing business logic.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>lld</category>
      <category>systemdesign</category>
      <category>softwareengineering</category>
      <category>codinginterview</category>
    </item>
    <item>
      <title>LLD Object-Oriented Design: Inheritance (When to Use It and When to Avoid It)</title>
      <dc:creator>Saras Growth Space</dc:creator>
      <pubDate>Fri, 22 May 2026 15:00:00 +0000</pubDate>
      <link>https://dev.to/saras_growth_space/lld-object-oriented-design-inheritance-when-to-use-it-and-when-to-avoid-it-41ll</link>
      <guid>https://dev.to/saras_growth_space/lld-object-oriented-design-inheritance-when-to-use-it-and-when-to-avoid-it-41ll</guid>
      <description>&lt;p&gt;After understanding how objects protect their state through encapsulation, the next natural step is learning how objects can &lt;strong&gt;reuse and extend behavior&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This is where inheritance comes in.&lt;/p&gt;

&lt;p&gt;However, inheritance is one of the most commonly misused concepts in object-oriented design.&lt;/p&gt;




&lt;h2&gt;
  
  
  What is Inheritance?
&lt;/h2&gt;

&lt;p&gt;Inheritance is a mechanism where:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A class acquires properties and behavior of another class.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This allows reuse and extension of existing behavior.&lt;/p&gt;




&lt;h2&gt;
  
  
  Basic Example
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;eat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Eating&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Animal&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;bark&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Barking&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Dog&lt;/code&gt; inherits from &lt;code&gt;Animal&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Dog automatically gets &lt;code&gt;eat()&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Why Inheritance Exists
&lt;/h2&gt;

&lt;p&gt;Inheritance is used for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;code reuse&lt;/li&gt;
&lt;li&gt;representing hierarchical relationships&lt;/li&gt;
&lt;li&gt;extending existing behavior&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It models an &lt;strong&gt;“is-a” relationship&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dog is an Animal&lt;/li&gt;
&lt;li&gt;Car is a Vehicle&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  The Key Idea: is-a Relationship
&lt;/h2&gt;

&lt;p&gt;Inheritance only makes sense when:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The child class is truly a specialized version of the parent class.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Good Use Case
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Payment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;process&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;pass&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CardPayment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Payment&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;process&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Processing card payment&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CardPayment is a Payment&lt;/li&gt;
&lt;li&gt;same contract, different behavior&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  The Hidden Risk of Inheritance
&lt;/h2&gt;

&lt;p&gt;Inheritance creates a strong coupling between classes.&lt;/p&gt;

&lt;p&gt;This means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;changes in parent affect child&lt;/li&gt;
&lt;li&gt;child depends heavily on parent structure&lt;/li&gt;
&lt;li&gt;hierarchy becomes rigid over time&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Bad Example
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Bird&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;fly&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Flying&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Penguin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Bird&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;pass&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Problem:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Penguin cannot fly&lt;/li&gt;
&lt;li&gt;but inherits fly behavior anyway&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This breaks the model.&lt;/p&gt;




&lt;h2&gt;
  
  
  Core Problem: Forced Behavior
&lt;/h2&gt;

&lt;p&gt;Inheritance can force unwanted behavior into child classes.&lt;/p&gt;

&lt;p&gt;This leads to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;incorrect modeling&lt;/li&gt;
&lt;li&gt;broken assumptions&lt;/li&gt;
&lt;li&gt;fragile systems&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Why Inheritance Breaks at Scale
&lt;/h2&gt;

&lt;p&gt;In real systems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;behavior varies widely&lt;/li&gt;
&lt;li&gt;rules change frequently&lt;/li&gt;
&lt;li&gt;strict hierarchies become restrictive&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As systems grow:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;inheritance trees become difficult to maintain&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Better Alternative: Think Before Inheriting
&lt;/h2&gt;

&lt;p&gt;Before using inheritance, ask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Is this truly an is-a relationship, or just shared behavior?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If it is shared behavior:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;composition is usually better&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Conceptual Insight
&lt;/h2&gt;

&lt;p&gt;Inheritance is not about reuse alone.&lt;/p&gt;

&lt;p&gt;It is about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;hierarchy&lt;/li&gt;
&lt;li&gt;substitution&lt;/li&gt;
&lt;li&gt;behavioral correctness&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  When Inheritance Works Well
&lt;/h2&gt;

&lt;p&gt;Use inheritance when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;behavior is stable&lt;/li&gt;
&lt;li&gt;hierarchy is clear&lt;/li&gt;
&lt;li&gt;substitution is valid&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Payment methods&lt;/li&gt;
&lt;li&gt;Notification types&lt;/li&gt;
&lt;li&gt;Base response models&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  When to Avoid Inheritance
&lt;/h2&gt;

&lt;p&gt;Avoid inheritance when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;behavior differs significantly&lt;/li&gt;
&lt;li&gt;future variation is expected&lt;/li&gt;
&lt;li&gt;relationship is not truly hierarchical&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Design Principle
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Inheritance should represent natural classification, not convenience-based reuse.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Real System Thinking
&lt;/h2&gt;

&lt;p&gt;In production systems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;inheritance is used sparingly&lt;/li&gt;
&lt;li&gt;composition is preferred for flexibility&lt;/li&gt;
&lt;li&gt;interfaces often replace deep hierarchies&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  One-Line Takeaway
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Inheritance should only be used when the child truly is a specialized form of the parent without violating expected behavior.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>lld</category>
      <category>systemdesign</category>
      <category>codinginterview</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>LLD Object-Oriented Design: Encapsulation (Protecting State and Behavior)</title>
      <dc:creator>Saras Growth Space</dc:creator>
      <pubDate>Thu, 21 May 2026 15:00:00 +0000</pubDate>
      <link>https://dev.to/saras_growth_space/lld-object-oriented-design-encapsulation-protecting-state-and-behavior-1d9n</link>
      <guid>https://dev.to/saras_growth_space/lld-object-oriented-design-encapsulation-protecting-state-and-behavior-1d9n</guid>
      <description>&lt;p&gt;Once you understand classes and objects, the next critical step in object-oriented design is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Controlling how internal state is accessed and modified.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is where &lt;strong&gt;encapsulation&lt;/strong&gt; becomes essential.&lt;/p&gt;




&lt;h2&gt;
  
  
  What is Encapsulation?
&lt;/h2&gt;

&lt;p&gt;Encapsulation means:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Keeping data (state) and methods (behavior) together, while controlling direct access to internal state.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It is not just about “hiding variables”.&lt;/p&gt;

&lt;p&gt;It is about &lt;strong&gt;protecting the integrity of an object&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Encapsulation Matters
&lt;/h2&gt;

&lt;p&gt;Without encapsulation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;any part of the system can modify state directly&lt;/li&gt;
&lt;li&gt;rules can be bypassed&lt;/li&gt;
&lt;li&gt;invalid states become possible&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With encapsulation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;object controls its own data&lt;/li&gt;
&lt;li&gt;rules are enforced in one place&lt;/li&gt;
&lt;li&gt;system becomes predictable&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Bad Design: No Encapsulation
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BankAccount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now anyone can do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;account&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This breaks business rules completely.&lt;/p&gt;




&lt;h2&gt;
  
  
  Good Design: Encapsulation
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BankAccount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;deposit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Invalid amount&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_balance&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_balance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_balance&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;state is protected&lt;/li&gt;
&lt;li&gt;modifications are controlled&lt;/li&gt;
&lt;li&gt;validation is enforced&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Key Idea: Control Through Methods
&lt;/h2&gt;

&lt;p&gt;Instead of allowing direct access:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You expose controlled behavior.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So instead of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;account.balance = X&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You do:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;account.deposit(X)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Encapsulation in Real Systems
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Example: Order System
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;CREATED&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;mark_paid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_status&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;CREATED&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Invalid transition&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;PAID&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;status cannot be changed freely&lt;/li&gt;
&lt;li&gt;only valid transitions are allowed&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  What Encapsulation Really Protects
&lt;/h2&gt;

&lt;p&gt;Encapsulation protects:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. State Integrity
&lt;/h3&gt;

&lt;p&gt;Prevents invalid data.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Business Rules
&lt;/h3&gt;

&lt;p&gt;Ensures rules are always applied.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. System Consistency
&lt;/h3&gt;

&lt;p&gt;Keeps objects in valid states.&lt;/p&gt;




&lt;h2&gt;
  
  
  Encapsulation vs Data Hiding (Important Distinction)
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Concept&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Data Hiding&lt;/td&gt;
&lt;td&gt;Restrict direct access to fields&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Encapsulation&lt;/td&gt;
&lt;td&gt;Bundle + control state through behavior&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Encapsulation is broader and more important in LLD.&lt;/p&gt;




&lt;h2&gt;
  
  
  Common Mistake: Getters/Setters Everywhere
&lt;/h2&gt;

&lt;p&gt;Beginners often do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;set_name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This does NOT add real encapsulation.&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;no validation&lt;/li&gt;
&lt;li&gt;no rules enforced&lt;/li&gt;
&lt;li&gt;still exposes raw state&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Better Thinking
&lt;/h2&gt;

&lt;p&gt;Instead of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;“How do I expose data?”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“What operations should be allowed on this object?”&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Encapsulation in System Design
&lt;/h2&gt;

&lt;p&gt;In real systems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;payment status cannot be directly modified&lt;/li&gt;
&lt;li&gt;order state transitions must follow rules&lt;/li&gt;
&lt;li&gt;account balances cannot be arbitrary&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Encapsulation ensures these constraints are always enforced.&lt;/p&gt;




&lt;h2&gt;
  
  
  Design Principle
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Objects should protect their own state and expose only meaningful behavior.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Why Encapsulation is Critical
&lt;/h2&gt;

&lt;p&gt;Without it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;systems become fragile&lt;/li&gt;
&lt;li&gt;bugs become unpredictable&lt;/li&gt;
&lt;li&gt;debugging becomes difficult&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;objects become reliable units&lt;/li&gt;
&lt;li&gt;system behavior becomes predictable&lt;/li&gt;
&lt;li&gt;design becomes scalable&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  One-Line Takeaway
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Encapsulation ensures that an object controls its own state and exposes only safe, meaningful operations.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>lld</category>
      <category>systemdesign</category>
      <category>softwareengineering</category>
      <category>codinginterview</category>
    </item>
    <item>
      <title>LLD Object-Oriented Design: Classes &amp; Objects (Deep Understanding)</title>
      <dc:creator>Saras Growth Space</dc:creator>
      <pubDate>Wed, 20 May 2026 15:00:00 +0000</pubDate>
      <link>https://dev.to/saras_growth_space/lld-object-oriented-design-classes-objects-deep-understanding-4jp1</link>
      <guid>https://dev.to/saras_growth_space/lld-object-oriented-design-classes-objects-deep-understanding-4jp1</guid>
      <description>&lt;p&gt;After shifting your thinking toward objects and responsibilities, the next step is to understand the most basic building block of object-oriented design:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Classes and objects are not just syntax — they are a way to model real-world systems.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Many people learn them early in programming, but never truly understand their design meaning in LLD.&lt;/p&gt;




&lt;h2&gt;
  
  
  What is a Class Really?
&lt;/h2&gt;

&lt;p&gt;A class is not just a template for code.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A class is a &lt;strong&gt;blueprint for behavior and state of a real-world entity&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It defines:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;what data an entity holds (state)&lt;/li&gt;
&lt;li&gt;what it can do (behavior)&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BankAccount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;deposit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;balance&lt;/code&gt; → state&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;deposit()&lt;/code&gt; → behavior&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  What is an Object?
&lt;/h2&gt;

&lt;p&gt;An object is a real instance created from a class.&lt;/p&gt;

&lt;p&gt;It represents a &lt;strong&gt;specific entity in the system with actual data&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;account1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;BankAccount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;account2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;BankAccount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;12000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;account1&lt;/code&gt; → has its own state (5000)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;account2&lt;/code&gt; → has its own state (12000)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Same class, different reality.&lt;/p&gt;




&lt;h2&gt;
  
  
  Key Insight: Class vs Object
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Concept&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Class&lt;/td&gt;
&lt;td&gt;Blueprint / definition&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Object&lt;/td&gt;
&lt;td&gt;Real instance / live entity&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A class defines structure.&lt;br&gt;
An object carries actual data.&lt;/p&gt;


&lt;h2&gt;
  
  
  Why This Matters in LLD
&lt;/h2&gt;

&lt;p&gt;In low-level design, systems are built using objects that represent real entities.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;
&lt;h3&gt;
  
  
  Food Delivery System
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;User → object&lt;/li&gt;
&lt;li&gt;Order → object&lt;/li&gt;
&lt;li&gt;Restaurant → object&lt;/li&gt;
&lt;li&gt;DeliveryPartner → object&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each object:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;holds state&lt;/li&gt;
&lt;li&gt;performs behavior&lt;/li&gt;
&lt;li&gt;interacts with other objects&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  State vs Behavior (Critical Distinction)
&lt;/h2&gt;
&lt;h3&gt;
  
  
  State
&lt;/h3&gt;

&lt;p&gt;Represents data held by an object.&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;balance in bank account&lt;/li&gt;
&lt;li&gt;order status&lt;/li&gt;
&lt;li&gt;user details&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;
  
  
  Behavior
&lt;/h3&gt;

&lt;p&gt;Represents actions an object can perform.&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;deposit money&lt;/li&gt;
&lt;li&gt;place order&lt;/li&gt;
&lt;li&gt;assign delivery&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;
  
  
  Rule of Thumb
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;State tells “what it is”, behavior tells “what it does”.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;h2&gt;
  
  
  Common Mistake: Passive Data Classes
&lt;/h2&gt;

&lt;p&gt;Beginners often design classes like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then put all logic outside.&lt;/p&gt;

&lt;p&gt;This leads to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;anemic models&lt;/li&gt;
&lt;li&gt;scattered business logic&lt;/li&gt;
&lt;li&gt;hard-to-maintain systems&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Better Approach: Active Objects
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;mark_paid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;CREATED&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Invalid state&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;PAID&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;object controls its state&lt;/li&gt;
&lt;li&gt;rules are enforced locally&lt;/li&gt;
&lt;li&gt;invalid transitions are prevented&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Core Design Principle
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Objects should manage their own state and behavior.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Not:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;external services manipulating internal state freely&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Why Objects Make Systems Scalable
&lt;/h2&gt;

&lt;p&gt;When systems grow:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;functions become unmanageable&lt;/li&gt;
&lt;li&gt;shared state becomes dangerous&lt;/li&gt;
&lt;li&gt;logic becomes scattered&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Objects solve this by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;encapsulating state&lt;/li&gt;
&lt;li&gt;bundling behavior&lt;/li&gt;
&lt;li&gt;reducing global complexity&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Real-World Mapping
&lt;/h2&gt;

&lt;p&gt;Think of objects as real entities:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;System&lt;/th&gt;
&lt;th&gt;Object&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Bank System&lt;/td&gt;
&lt;td&gt;Account&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;E-commerce&lt;/td&gt;
&lt;td&gt;Order&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Delivery&lt;/td&gt;
&lt;td&gt;Rider&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Booking&lt;/td&gt;
&lt;td&gt;Ticket&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Each object has:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;identity&lt;/li&gt;
&lt;li&gt;state&lt;/li&gt;
&lt;li&gt;behavior&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Design Intuition
&lt;/h2&gt;

&lt;p&gt;When designing a system, always ask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“What does this entity know, and what can it do?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If the answer is unclear, the design is incomplete.&lt;/p&gt;




&lt;h2&gt;
  
  
  One-Line Takeaway
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Classes define structure, objects represent real instances, and together they model real-world systems through state and behavior.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>lld</category>
      <category>systemdesign</category>
      <category>softwareengineering</category>
      <category>codinginterview</category>
    </item>
    <item>
      <title>Google I/O 2026 Made Me Realize AI Agents Are Becoming Real Development Infrastructure</title>
      <dc:creator>Saras Growth Space</dc:creator>
      <pubDate>Wed, 20 May 2026 10:00:19 +0000</pubDate>
      <link>https://dev.to/saras_growth_space/google-io-2026-made-me-realize-ai-agents-are-becoming-real-development-infrastructure-42me</link>
      <guid>https://dev.to/saras_growth_space/google-io-2026-made-me-realize-ai-agents-are-becoming-real-development-infrastructure-42me</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/challenges/google-io-writing-2026-05-19"&gt;Google I/O Writing Challenge&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Google I/O 2026 made one thing increasingly clear to me:&lt;/p&gt;

&lt;p&gt;AI is slowly moving beyond isolated chatbot experiences and becoming part of actual development infrastructure.&lt;/p&gt;

&lt;p&gt;For a long time, most conversations around AI focused primarily on model intelligence:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;benchmark improvements,&lt;/li&gt;
&lt;li&gt;larger context windows,&lt;/li&gt;
&lt;li&gt;better reasoning,&lt;/li&gt;
&lt;li&gt;faster responses,&lt;/li&gt;
&lt;li&gt;and multimodal capabilities.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those advancements matter, but this year’s announcements highlighted something equally important:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The ecosystem around AI is becoming significantly more usable for developers.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And I think that shift may ultimately matter more than raw model capability alone.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Most Important Change Isn't Just Smarter Models
&lt;/h2&gt;

&lt;p&gt;Modern AI systems are no longer just standalone assistants.&lt;/p&gt;

&lt;p&gt;They are increasingly becoming:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;workflow participants,&lt;/li&gt;
&lt;li&gt;orchestration layers,&lt;/li&gt;
&lt;li&gt;development accelerators,&lt;/li&gt;
&lt;li&gt;multimodal interfaces,&lt;/li&gt;
&lt;li&gt;and infrastructure components developers can build around.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That changes the conversation entirely.&lt;/p&gt;

&lt;p&gt;The value of AI is no longer only about asking better questions in a chat window.&lt;/p&gt;

&lt;p&gt;The real transformation begins when AI systems can integrate into actual software workflows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;connecting tools,&lt;/li&gt;
&lt;li&gt;handling multiple input types,&lt;/li&gt;
&lt;li&gt;assisting development pipelines,&lt;/li&gt;
&lt;li&gt;automating repetitive engineering tasks,&lt;/li&gt;
&lt;li&gt;and enabling faster iteration cycles.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Google I/O 2026 strongly reinforced this direction.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Ecosystem Layer Is Becoming the Real Advantage
&lt;/h2&gt;

&lt;p&gt;One of the biggest takeaways from this year’s announcements is that developer ecosystems are becoming just as important as the underlying models themselves.&lt;/p&gt;

&lt;p&gt;Because eventually:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;APIs matter,&lt;/li&gt;
&lt;li&gt;tooling matters,&lt;/li&gt;
&lt;li&gt;integrations matter,&lt;/li&gt;
&lt;li&gt;orchestration matters,&lt;/li&gt;
&lt;li&gt;iteration speed matters,&lt;/li&gt;
&lt;li&gt;and developer experience matters.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A highly capable model becomes dramatically more useful when developers can rapidly experiment, prototype, and integrate it into real systems.&lt;/p&gt;

&lt;p&gt;That is why platforms like Google AI Studio feel important.&lt;/p&gt;

&lt;p&gt;The barrier between:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;idea → prototype → working system&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;is getting smaller.&lt;/p&gt;

&lt;p&gt;And that changes who gets to build.&lt;/p&gt;




&lt;h2&gt;
  
  
  AI Agents Are Quietly Becoming Workflow Infrastructure
&lt;/h2&gt;

&lt;p&gt;What stood out most to me was how AI agents are evolving beyond simple conversational interfaces.&lt;/p&gt;

&lt;p&gt;Modern AI systems are increasingly expected to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;reason across tools,&lt;/li&gt;
&lt;li&gt;manage context,&lt;/li&gt;
&lt;li&gt;interact with workflows,&lt;/li&gt;
&lt;li&gt;process multimodal inputs,&lt;/li&gt;
&lt;li&gt;and coordinate tasks dynamically.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That starts looking less like a chatbot feature and more like infrastructure.&lt;/p&gt;

&lt;p&gt;The interesting part is not just that AI can generate responses.&lt;/p&gt;

&lt;p&gt;It’s that AI can increasingly participate inside larger systems.&lt;/p&gt;

&lt;p&gt;That opens up entirely different possibilities for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;software engineering,&lt;/li&gt;
&lt;li&gt;automation,&lt;/li&gt;
&lt;li&gt;productivity tooling,&lt;/li&gt;
&lt;li&gt;research workflows,&lt;/li&gt;
&lt;li&gt;and intelligent developer platforms.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Faster Experimentation Changes Everything
&lt;/h2&gt;

&lt;p&gt;One underrated aspect of modern AI tooling is how much it reduces experimentation friction.&lt;/p&gt;

&lt;p&gt;Historically, building intelligent systems often required:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;significant infrastructure setup,&lt;/li&gt;
&lt;li&gt;complex integrations,&lt;/li&gt;
&lt;li&gt;model management,&lt;/li&gt;
&lt;li&gt;deployment pipelines,&lt;/li&gt;
&lt;li&gt;and specialized expertise.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now the development loop is becoming much faster.&lt;/p&gt;

&lt;p&gt;Developers can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;prototype quickly,&lt;/li&gt;
&lt;li&gt;iterate faster,&lt;/li&gt;
&lt;li&gt;test workflows rapidly,&lt;/li&gt;
&lt;li&gt;and validate ideas with significantly less overhead.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That acceleration may end up being one of the most important long-term impacts of the current AI ecosystem shift.&lt;/p&gt;

&lt;p&gt;Because innovation compounds when experimentation becomes easier.&lt;/p&gt;




&lt;h2&gt;
  
  
  But The Challenges Are Still Very Real
&lt;/h2&gt;

&lt;p&gt;At the same time, the current state of AI systems still comes with major engineering challenges:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;hallucinations,&lt;/li&gt;
&lt;li&gt;evaluation complexity,&lt;/li&gt;
&lt;li&gt;reliability issues,&lt;/li&gt;
&lt;li&gt;orchestration difficulty,&lt;/li&gt;
&lt;li&gt;debugging problems,&lt;/li&gt;
&lt;li&gt;and unpredictable behavior.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;AI agents add even more complexity because they combine:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;reasoning,&lt;/li&gt;
&lt;li&gt;memory,&lt;/li&gt;
&lt;li&gt;workflows,&lt;/li&gt;
&lt;li&gt;tool usage,&lt;/li&gt;
&lt;li&gt;and autonomous decision-making.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Building reliable agentic systems is still difficult.&lt;/p&gt;

&lt;p&gt;And that’s exactly why infrastructure, tooling, and ecosystem maturity matter so much right now.&lt;/p&gt;

&lt;p&gt;The easier these systems become to evaluate, debug, orchestrate, and integrate responsibly, the more useful they become for real-world software development.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Bigger Shift
&lt;/h2&gt;

&lt;p&gt;The most interesting part of Google I/O 2026 wasn’t a single feature announcement.&lt;/p&gt;

&lt;p&gt;It was the broader direction.&lt;/p&gt;

&lt;p&gt;AI is gradually evolving from:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;“a tool developers occasionally use”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;into:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;“a software layer developers build on top of.”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That feels like a meaningful transition.&lt;/p&gt;

&lt;p&gt;The future of AI will likely depend not only on model intelligence, but also on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ecosystem quality,&lt;/li&gt;
&lt;li&gt;developer accessibility,&lt;/li&gt;
&lt;li&gt;infrastructure maturity,&lt;/li&gt;
&lt;li&gt;orchestration tooling,&lt;/li&gt;
&lt;li&gt;and the ability to transform ideas into working systems quickly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And that shift may ultimately shape the next generation of software development far more than model benchmarks alone.&lt;/p&gt;




&lt;p&gt;Thanks for reading!&lt;br&gt;&lt;br&gt;
What was the most interesting Google I/O 2026 announcement or trend for you as a developer?&lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>googleiochallenge</category>
      <category>ai</category>
      <category>agents</category>
    </item>
    <item>
      <title>LLD Object-Oriented Design: Thinking in Objects, Not Code</title>
      <dc:creator>Saras Growth Space</dc:creator>
      <pubDate>Tue, 19 May 2026 15:00:00 +0000</pubDate>
      <link>https://dev.to/saras_growth_space/lld-object-oriented-design-thinking-in-objects-not-code-337p</link>
      <guid>https://dev.to/saras_growth_space/lld-object-oriented-design-thinking-in-objects-not-code-337p</guid>
      <description>&lt;p&gt;Low-Level Design is not about writing classes or memorizing patterns.&lt;/p&gt;

&lt;p&gt;It is about a fundamental shift in thinking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Designing systems as a collection of &lt;strong&gt;responsibilities&lt;/strong&gt;, not functions.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Most beginners start with code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;functions&lt;/li&gt;
&lt;li&gt;APIs&lt;/li&gt;
&lt;li&gt;logic&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But real system design starts before that. It starts with how you &lt;strong&gt;model the problem itself&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Object Thinking Matters
&lt;/h2&gt;

&lt;p&gt;A system designed around functions tends to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;scatter logic across multiple places&lt;/li&gt;
&lt;li&gt;lose control over state&lt;/li&gt;
&lt;li&gt;become hard to modify safely&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A system designed around objects tends to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;keep data and behavior together&lt;/li&gt;
&lt;li&gt;enforce rules at one place&lt;/li&gt;
&lt;li&gt;make behavior predictable&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The difference is not syntactic—it is structural.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Wrong Mental Model (Function-Centric Design)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;deposit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;account&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;withdraw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;account&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;update_balance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;account&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At first glance, this looks simple and readable.&lt;/p&gt;

&lt;p&gt;But it raises deeper design issues:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Who owns the account state?&lt;/li&gt;
&lt;li&gt;Where are validation rules enforced?&lt;/li&gt;
&lt;li&gt;What prevents invalid updates?&lt;/li&gt;
&lt;li&gt;What happens when business rules change?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The logic is distributed, not owned.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Correct Mental Model (Object-Centric Design)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BankAccount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;deposit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="bp"&gt;...&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;withdraw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the design changes fundamentally:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;state and behavior are encapsulated together&lt;/li&gt;
&lt;li&gt;rules are enforced inside the object&lt;/li&gt;
&lt;li&gt;external code interacts through controlled methods&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The system becomes &lt;strong&gt;self-governing at the object level&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Core Idea: Responsibility Ownership
&lt;/h2&gt;

&lt;p&gt;The most important question in object-oriented design is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Which object owns this responsibility?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Not:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;where should this function go&lt;/li&gt;
&lt;li&gt;how should I structure files&lt;/li&gt;
&lt;li&gt;how many layers should I create&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instead:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;which entity is responsible for this behavior in the domain?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This shift determines the quality of the entire design.&lt;/p&gt;




&lt;h2&gt;
  
  
  Objects Represent Real-World Systems
&lt;/h2&gt;

&lt;p&gt;A good mental model is to map systems into interacting entities:&lt;/p&gt;

&lt;h3&gt;
  
  
  Example: Food Delivery System
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;User → initiates actions&lt;/li&gt;
&lt;li&gt;Restaurant → prepares food&lt;/li&gt;
&lt;li&gt;Order → maintains lifecycle state&lt;/li&gt;
&lt;li&gt;DeliveryPartner → fulfills delivery&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each object:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;owns state&lt;/li&gt;
&lt;li&gt;exposes behavior relevant to its responsibility&lt;/li&gt;
&lt;li&gt;does not manage unrelated logic&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Class vs Object (Core Understanding)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Class
&lt;/h3&gt;

&lt;p&gt;A blueprint that defines structure and behavior.&lt;/p&gt;

&lt;h3&gt;
  
  
  Object
&lt;/h3&gt;

&lt;p&gt;A real instance with actual state.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BankAccount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Objects created from this class:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Account A → 5000&lt;/li&gt;
&lt;li&gt;Account B → 12000&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Same structure, different state.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Most Important Rule in OOD
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;A class should represent a single, meaningful responsibility.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When a class:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;handles too many responsibilities → it becomes fragile&lt;/li&gt;
&lt;li&gt;knows too much about unrelated domains → it becomes hard to maintain&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Good design is not about size. It is about focus.&lt;/p&gt;




&lt;h2&gt;
  
  
  A Practical Design Flow
&lt;/h2&gt;

&lt;p&gt;Before writing code, a structured approach helps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Understand the problem clearly&lt;/li&gt;
&lt;li&gt;Identify core entities&lt;/li&gt;
&lt;li&gt;Assign responsibilities to each entity&lt;/li&gt;
&lt;li&gt;Define interactions between entities&lt;/li&gt;
&lt;li&gt;Only then move to implementation&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Skipping these steps leads to incorrect abstractions and redesign later.&lt;/p&gt;




&lt;h2&gt;
  
  
  Real Insight
&lt;/h2&gt;

&lt;p&gt;In object-oriented design, correctness is not about syntax or patterns.&lt;/p&gt;

&lt;p&gt;It is about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;clarity of responsibilities&lt;/li&gt;
&lt;li&gt;consistency of state management&lt;/li&gt;
&lt;li&gt;predictability of interactions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Good design is what remains stable when requirements change.&lt;/p&gt;




&lt;h2&gt;
  
  
  One-Line Takeaway
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Object-oriented design begins when systems are modeled around responsibilities, not functions.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>lld</category>
      <category>systemdesign</category>
      <category>softwareengineering</category>
      <category>codinginterview</category>
    </item>
    <item>
      <title>LLD Foundations: Trade-offs Thinking (how real design decisions are made)</title>
      <dc:creator>Saras Growth Space</dc:creator>
      <pubDate>Mon, 18 May 2026 15:00:00 +0000</pubDate>
      <link>https://dev.to/saras_growth_space/lld-foundations-trade-offs-thinking-how-real-design-decisions-are-made-4jhm</link>
      <guid>https://dev.to/saras_growth_space/lld-foundations-trade-offs-thinking-how-real-design-decisions-are-made-4jhm</guid>
      <description>&lt;p&gt;Up to now, you’ve learned:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;how to structure systems&lt;/li&gt;
&lt;li&gt;how to apply principles&lt;/li&gt;
&lt;li&gt;how to keep designs clean&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But there is one reality that changes everything:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;There is no perfect system design.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Every decision you make improves something and weakens something else.&lt;/p&gt;

&lt;p&gt;Understanding this is what separates:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;someone who knows concepts
from&lt;/li&gt;
&lt;li&gt;someone who can design real systems&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  The illusion of the “best solution”
&lt;/h2&gt;

&lt;p&gt;A common beginner mindset is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“What is the best design for this problem?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In reality, that question is incomplete.&lt;/p&gt;

&lt;p&gt;A better question is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“What am I optimizing for, and what am I willing to compromise?”&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  What is a trade-off?
&lt;/h2&gt;

&lt;p&gt;A trade-off means:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You gain one benefit by accepting a cost somewhere else.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Common trade-offs in systems
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Consistency vs Availability
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Strong consistency → always correct data&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;slower&lt;/li&gt;
&lt;li&gt;less available during failures&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;High availability → system always responds&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;may return slightly outdated data&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Example:&lt;br&gt;
In a food delivery system, availability is often prioritized.&lt;br&gt;
A slightly delayed order status is acceptable.&lt;br&gt;
A system that doesn’t respond is not.&lt;/p&gt;




&lt;h3&gt;
  
  
  2. Performance vs Cost
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;More servers → faster responses&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;higher infrastructure cost&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Fewer resources → lower cost&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;slower performance&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  3. Simplicity vs Flexibility
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Simple design&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;easier to build and maintain&lt;/li&gt;
&lt;li&gt;harder to extend later&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Flexible design&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;easier to extend&lt;/li&gt;
&lt;li&gt;more complex initially&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h3&gt;
  
  
  4. Read vs Write optimization
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Indexing improves read speed&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;but slows down writes&lt;/li&gt;
&lt;li&gt;increases storage usage&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h2&gt;
  
  
  Why trade-offs matter
&lt;/h2&gt;

&lt;p&gt;Every design decision you make:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;impacts scalability&lt;/li&gt;
&lt;li&gt;affects user experience&lt;/li&gt;
&lt;li&gt;changes system complexity&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ignoring trade-offs leads to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;over-engineering&lt;/li&gt;
&lt;li&gt;under-performing systems&lt;/li&gt;
&lt;li&gt;unexpected failures at scale&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  How to think in trade-offs
&lt;/h2&gt;

&lt;p&gt;Instead of asking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Is this design correct?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ask:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What does this design optimize?&lt;/li&gt;
&lt;li&gt;What does it sacrifice?&lt;/li&gt;
&lt;li&gt;Is that acceptable for this system?&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  A practical example
&lt;/h2&gt;

&lt;p&gt;Designing a food delivery system:&lt;/p&gt;

&lt;p&gt;You might choose:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;High availability&lt;/li&gt;
&lt;li&gt;Eventual consistency&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;Because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;users prefer a working system&lt;/li&gt;
&lt;li&gt;slight delays in updates are acceptable&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is a conscious trade-off, not a compromise by accident.&lt;/p&gt;




&lt;h2&gt;
  
  
  A subtle but critical shift
&lt;/h2&gt;

&lt;p&gt;Beginners try to avoid trade-offs.&lt;/p&gt;

&lt;p&gt;Experienced engineers:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Make trade-offs deliberately.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Closing thought
&lt;/h2&gt;

&lt;p&gt;Good design is not about eliminating compromises.&lt;/p&gt;

&lt;p&gt;It’s about choosing the &lt;strong&gt;right compromises for the problem you are solving&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>lld</category>
      <category>systemdesign</category>
      <category>softwareengineering</category>
      <category>codinginterview</category>
    </item>
    <item>
      <title>LLD Foundations: DRY, KISS, YAGNI (practical rules for everyday design)</title>
      <dc:creator>Saras Growth Space</dc:creator>
      <pubDate>Sun, 17 May 2026 15:00:00 +0000</pubDate>
      <link>https://dev.to/saras_growth_space/lld-foundations-dry-kiss-yagni-practical-rules-for-everyday-design-53ab</link>
      <guid>https://dev.to/saras_growth_space/lld-foundations-dry-kiss-yagni-practical-rules-for-everyday-design-53ab</guid>
      <description>&lt;p&gt;So far, you’ve seen structured principles like SOLID and concepts like cohesion and coupling.&lt;/p&gt;

&lt;p&gt;But in day-to-day development, you don’t always think in formal principles.&lt;/p&gt;

&lt;p&gt;Instead, you rely on simple rules that guide decisions quickly.&lt;/p&gt;

&lt;p&gt;Three of the most important ones are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;DRY (Don’t Repeat Yourself)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;KISS (Keep It Simple)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;YAGNI (You Aren’t Gonna Need It)&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These look simple, but they prevent a large number of real-world design issues.&lt;/p&gt;




&lt;h2&gt;
  
  
  DRY — Don’t Repeat Yourself
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Every piece of knowledge should have a single, unambiguous source.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  What goes wrong without DRY
&lt;/h3&gt;

&lt;p&gt;You implement pricing logic in multiple places:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;checkout flow&lt;/li&gt;
&lt;li&gt;order summary&lt;/li&gt;
&lt;li&gt;invoice generation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Initially, everything works.&lt;/p&gt;

&lt;p&gt;Later:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;tax calculation changes&lt;/li&gt;
&lt;li&gt;discount rules update&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now you must update logic in multiple places.&lt;/p&gt;

&lt;p&gt;Miss one, and your system behaves inconsistently.&lt;/p&gt;




&lt;h3&gt;
  
  
  Applying DRY
&lt;/h3&gt;

&lt;p&gt;Centralize logic:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PriceService:
- calculate_price(order)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;one source of truth&lt;/li&gt;
&lt;li&gt;consistent behavior across the system&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Important nuance
&lt;/h3&gt;

&lt;p&gt;DRY is not just about avoiding duplicate code.&lt;/p&gt;

&lt;p&gt;It’s about:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Avoiding duplicate &lt;strong&gt;logic and knowledge&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  Common mistake
&lt;/h3&gt;

&lt;p&gt;Over-applying DRY too early:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;creating generic abstractions&lt;/li&gt;
&lt;li&gt;forcing unrelated logic into one place&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This leads to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;complexity&lt;/li&gt;
&lt;li&gt;harder readability&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  KISS — Keep It Simple
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Prefer simple solutions over complex ones.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  What goes wrong without KISS
&lt;/h3&gt;

&lt;p&gt;You design a simple feature using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;multiple design patterns&lt;/li&gt;
&lt;li&gt;deep abstractions&lt;/li&gt;
&lt;li&gt;unnecessary layers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The system becomes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;harder to understand&lt;/li&gt;
&lt;li&gt;slower to modify&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Applying KISS
&lt;/h3&gt;

&lt;p&gt;Choose the simplest approach that solves the problem.&lt;/p&gt;

&lt;p&gt;Sometimes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a simple class is enough&lt;/li&gt;
&lt;li&gt;a straightforward condition is fine&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Complexity should be introduced only when required.&lt;/p&gt;




&lt;h3&gt;
  
  
  Important nuance
&lt;/h3&gt;

&lt;p&gt;KISS does not mean:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;writing messy or unstructured code&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It means:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Avoiding unnecessary complexity&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  YAGNI — You Aren’t Gonna Need It
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Don’t build functionality until it is actually needed.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  What goes wrong without YAGNI
&lt;/h3&gt;

&lt;p&gt;While building an MVP, you add:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;multi-region support&lt;/li&gt;
&lt;li&gt;advanced recommendation system&lt;/li&gt;
&lt;li&gt;dynamic pricing engine&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of these are required immediately.&lt;/p&gt;

&lt;p&gt;Result:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;longer development time&lt;/li&gt;
&lt;li&gt;more bugs&lt;/li&gt;
&lt;li&gt;increased complexity&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Applying YAGNI
&lt;/h3&gt;

&lt;p&gt;Focus on current requirements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;build what is needed now&lt;/li&gt;
&lt;li&gt;leave extension points for future&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Do not implement features based on assumptions.&lt;/p&gt;




&lt;h3&gt;
  
  
  Important nuance
&lt;/h3&gt;

&lt;p&gt;YAGNI does not mean:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ignoring future scalability&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It means:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Don’t implement future features without real need&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  How these three work together
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;DRY → keeps logic consistent&lt;/li&gt;
&lt;li&gt;KISS → keeps design simple&lt;/li&gt;
&lt;li&gt;YAGNI → keeps scope controlled&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Together, they help you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;avoid over-engineering&lt;/li&gt;
&lt;li&gt;write maintainable code&lt;/li&gt;
&lt;li&gt;move faster without creating chaos&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  A practical way to use them
&lt;/h2&gt;

&lt;p&gt;When designing, ask:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Am I repeating logic? → DRY&lt;/li&gt;
&lt;li&gt;Am I overcomplicating this? → KISS&lt;/li&gt;
&lt;li&gt;Do I really need this right now? → YAGNI&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Closing thought
&lt;/h2&gt;

&lt;p&gt;Good design is not just about what you build.&lt;/p&gt;

&lt;p&gt;It’s also about what you &lt;strong&gt;choose not to build&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>lld</category>
      <category>systemdesign</category>
      <category>softwareengineering</category>
      <category>codinginterview</category>
    </item>
    <item>
      <title>LLD Foundations: Coupling vs Cohesion (how to judge if your design is actually good)</title>
      <dc:creator>Saras Growth Space</dc:creator>
      <pubDate>Sat, 16 May 2026 15:00:00 +0000</pubDate>
      <link>https://dev.to/saras_growth_space/lld-foundations-coupling-vs-cohesion-how-to-judge-if-your-design-is-actually-good-1ill</link>
      <guid>https://dev.to/saras_growth_space/lld-foundations-coupling-vs-cohesion-how-to-judge-if-your-design-is-actually-good-1ill</guid>
      <description>&lt;p&gt;Up to this point, you’ve learned:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;how to understand requirements&lt;/li&gt;
&lt;li&gt;how to break systems&lt;/li&gt;
&lt;li&gt;how to apply SOLID principles&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But a practical question still remains:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;How do you evaluate whether a design is good or not?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Two concepts help you answer that:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Cohesion&lt;/strong&gt; and &lt;strong&gt;Coupling&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  The hidden problem in most designs
&lt;/h2&gt;

&lt;p&gt;Consider this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OrderService:
- create_order()
- process_payment()
- send_email()
- generate_invoice()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At first glance, this may seem organized.&lt;/p&gt;

&lt;p&gt;All order-related actions are in one place.&lt;/p&gt;

&lt;p&gt;But look closer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;order creation&lt;/li&gt;
&lt;li&gt;payment processing&lt;/li&gt;
&lt;li&gt;notifications&lt;/li&gt;
&lt;li&gt;billing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are not the same responsibility.&lt;/p&gt;

&lt;p&gt;This is where design quality starts breaking.&lt;/p&gt;




&lt;h2&gt;
  
  
  Cohesion — how focused a component is
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Cohesion measures how closely related the responsibilities inside a module are.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  Low cohesion (bad design)
&lt;/h3&gt;

&lt;p&gt;A class doing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;multiple unrelated tasks&lt;/li&gt;
&lt;li&gt;mixing business logic with external concerns&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Like the previous example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;OrderService is doing everything&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This leads to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;harder understanding&lt;/li&gt;
&lt;li&gt;difficult testing&lt;/li&gt;
&lt;li&gt;risky changes&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  High cohesion (good design)
&lt;/h3&gt;

&lt;p&gt;Break responsibilities:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OrderService → create_order()
PaymentService → process_payment()
NotificationService → send_email()
InvoiceService → generate_invoice()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;each class has a single, clear purpose&lt;/li&gt;
&lt;li&gt;logic is easier to reason about&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Key insight
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;A cohesive class answers one question clearly.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Coupling — how dependent components are
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Coupling measures how much one component depends on others.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  High coupling (bad design)
&lt;/h3&gt;

&lt;p&gt;If &lt;code&gt;OrderService&lt;/code&gt; directly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;calls payment logic&lt;/li&gt;
&lt;li&gt;sends emails&lt;/li&gt;
&lt;li&gt;generates invoices&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;it depends on multiple systems&lt;/li&gt;
&lt;li&gt;any change in those systems affects it&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Low coupling (good design)
&lt;/h3&gt;

&lt;p&gt;Introduce separation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Services are independent&lt;/li&gt;
&lt;li&gt;Communication happens via clear interfaces&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Optionally, introduce an orchestrator:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OrderOrchestrator:
- create_order()
- process_payment()
- send_notification()
- generate_invoice()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;services don’t depend on each other&lt;/li&gt;
&lt;li&gt;flow is managed separately&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Key insight
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Low coupling reduces the ripple effect of changes.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  How cohesion and coupling work together
&lt;/h2&gt;

&lt;p&gt;Good design aims for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;High Cohesion&lt;/strong&gt; → each module is focused&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Low Coupling&lt;/strong&gt; → modules are independent&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you get both right:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;code is easier to maintain&lt;/li&gt;
&lt;li&gt;features are easier to add&lt;/li&gt;
&lt;li&gt;bugs are easier to isolate&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  A practical way to evaluate your design
&lt;/h2&gt;

&lt;p&gt;Ask yourself:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Does this class have more than one responsibility? → Cohesion issue&lt;/li&gt;
&lt;li&gt;Will a change in one part affect many others? → Coupling issue&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the answer is yes, your design needs refinement.&lt;/p&gt;




&lt;h2&gt;
  
  
  A subtle but important shift
&lt;/h2&gt;

&lt;p&gt;Beginners often think:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Everything in one place is easier.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Experienced engineers think:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Clear separation makes systems easier to evolve.”&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Closing thought
&lt;/h2&gt;

&lt;p&gt;Good design is not about adding more structure.&lt;/p&gt;

&lt;p&gt;It’s about placing responsibilities in the right place, and keeping dependencies under control.&lt;/p&gt;

</description>
      <category>lld</category>
      <category>systemdesign</category>
      <category>softwareengineering</category>
      <category>codinginterview</category>
    </item>
  </channel>
</rss>
