<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Atuljaiss on Medium]]></title>
        <description><![CDATA[Stories by Atuljaiss on Medium]]></description>
        <link>https://medium.com/@atuljaiss7?source=rss-18eb19ebb450------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ipyNmVi633y1CNyV8qYAAw.jpeg</url>
            <title>Stories by Atuljaiss on Medium</title>
            <link>https://medium.com/@atuljaiss7?source=rss-18eb19ebb450------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 17:51:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@atuljaiss7/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Decorator Pattern & Composite Pattern]]></title>
            <link>https://medium.com/@atuljaiss7/decorator-pattern-composite-pattern-45ea643f9b47?source=rss-18eb19ebb450------2</link>
            <guid isPermaLink="false">https://medium.com/p/45ea643f9b47</guid>
            <category><![CDATA[low-level-design]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Atuljaiss]]></dc:creator>
            <pubDate>Sun, 11 May 2025 17:32:28 GMT</pubDate>
            <atom:updated>2025-05-11T17:32:28.441Z</atom:updated>
            <content:encoded><![CDATA[<p>These two patterns often come up in real-world UI frameworks and component-based systems. Let’s break them down.</p><h3>🔷 Decorator Pattern</h3><h3>Definition:</h3><p>Decorator Pattern <strong>adds new behavior or responsibilities</strong> to an object <strong>dynamically</strong> without modifying its structure.</p><h3>When to Use:</h3><ul><li>You want to <strong>add features</strong> to objects <strong>without altering</strong> their class.</li><li>You want to follow <strong>Open-Closed Principle</strong>: open for extension, closed for modification.</li><li>You need to <strong>add behavior at runtime</strong>.</li></ul><h3>Real-Life Example:</h3><ul><li><strong>Coffee Ordering System</strong></li><li>Base: Espresso</li><li>Add-ons: Milk, Sugar, Whipped Cream<br> ➤ Each add-on wraps the coffee and adds cost/description.</li></ul><h3>Code Example (Java):</h3><pre>interface Coffee {<br>    String getDescription();<br>    double cost();<br>}<br>class SimpleCoffee implements Coffee {<br>    public String getDescription() { return &quot;Simple Coffee&quot;; }<br>    public double cost() { return 5; }<br>}<br>// Decorator class<br>abstract class CoffeeDecorator implements Coffee {<br>    protected Coffee coffee;<br>    CoffeeDecorator(Coffee coffee) {<br>        this.coffee = coffee;<br>    }<br>}<br>// Add Milk<br>class MilkDecorator extends CoffeeDecorator {<br>    MilkDecorator(Coffee coffee) { super(coffee); }<br>    public String getDescription() {<br>        return coffee.getDescription() + &quot;, Milk&quot;;<br>    }<br>    public double cost() {<br>        return coffee.cost() + 1.5;<br>    }<br>}<br>// Add Sugar<br>class SugarDecorator extends CoffeeDecorator {<br>    SugarDecorator(Coffee coffee) { super(coffee); }<br>    public String getDescription() {<br>        return coffee.getDescription() + &quot;, Sugar&quot;;<br>    }<br>    public double cost() {<br>        return coffee.cost() + 0.5;<br>    }<br>}</pre><h3>Usage:</h3><pre>Coffee coffee = new SimpleCoffee();<br>coffee = new MilkDecorator(coffee);<br>coffee = new SugarDecorator(coffee);<br><br>System.out.println(coffee.getDescription()); // Simple Coffee, Milk, Sugar<br>System.out.println(coffee.cost());           // 7.0</pre><h3>Diagram:</h3><pre>[Coffee] ← [SimpleCoffee]<br>      ↑<br>[CoffeeDecorator] ← [MilkDecorator], [SugarDecorator]</pre><h3>🔷 Composite Pattern</h3><h3>Definition:</h3><p>Composite Pattern <strong>treats individual objects and compositions of objects uniformly</strong>.<br>It lets clients work with individual items and groups <strong>in the same way</strong>.</p><h3>When to Use:</h3><ul><li>You have a <strong>tree-like structure</strong> (e.g., files and folders).</li><li>You want to allow <strong>clients to treat single items and groups the same</strong>.</li></ul><h3>Real-Life Example:</h3><p><strong>File System</strong></p><ul><li>File and Folder both implement the same interface.</li><li>Folder can contain files <strong>or other folders</strong>.</li><li>You can call show() on either.</li></ul><h3>Code Example (Java):</h3><pre>interface FileSystemComponent {<br>    void show();<br>}<br><br>class File implements FileSystemComponent {<br>    private String name;<br>    File(String name) { this.name = name; }<br>    public void show() {<br>        System.out.println(&quot;File: &quot; + name);<br>    }<br>}<br><br>class Folder implements FileSystemComponent {<br>    private String name;<br>    private List&lt;FileSystemComponent&gt; components = new ArrayList&lt;&gt;();<br>    Folder(String name) { this.name = name; }<br>    public void add(FileSystemComponent component) {<br>        components.add(component);<br>    }<br>    public void show() {<br>        System.out.println(&quot;Folder: &quot; + name);<br>        for (FileSystemComponent component : components) {<br>            component.show();<br>        }<br>    }<br>}</pre><h3>Usage:</h3><pre>File file1 = new File(&quot;file1.txt&quot;);<br>File file2 = new File(&quot;file2.txt&quot;);<br><br>Folder folder = new Folder(&quot;MyFolder&quot;);<br>folder.add(file1);<br>folder.add(file2);<br>folder.show();<br><br>// Output : <br><br>Folder: MyFolder<br>File: file1.txt<br>File: file2.txt</pre><h3>Diagram:</h3><pre>[FileSystemComponent]<br>       ↑<br> [File]   [Folder] → has List&lt;FileSystemComponent&gt;</pre><h3>Summary</h3><p>Pattern Purpose Example <strong>Decorator</strong> Add responsibilities to objects dynamically Coffee with milk &amp; sugar <strong>Composite</strong> Treat individual and group of objects uniformly File and folder tree</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45ea643f9b47" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Structural Patterns — What Are They?]]></title>
            <link>https://medium.com/@atuljaiss7/structural-patterns-what-are-they-9533dd98cf5d?source=rss-18eb19ebb450------2</link>
            <guid isPermaLink="false">https://medium.com/p/9533dd98cf5d</guid>
            <category><![CDATA[sofware-development]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[low-level-design]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[Atuljaiss]]></dc:creator>
            <pubDate>Sun, 27 Apr 2025 11:34:01 GMT</pubDate>
            <atom:updated>2025-04-27T11:34:01.295Z</atom:updated>
            <content:encoded><![CDATA[<h3>Structural Patterns — What Are They?</h3><p>Structural patterns are about <strong>how classes and objects are combined</strong> to form <strong>larger structures</strong> while keeping them <strong>flexible and efficient</strong>.<br><em> ➔ They mainly </em><strong><em>simplify relationships</em></strong><em> between objects.</em></p><p>Structure Design Patterns : <br> 🔹 Adapter Pattern<br> 🔹 Decorator Pattern<br> 🔹 Composite Pattern<br> 🔹 Facade Pattern<br> 🔹 Proxy Pattern<br> 🔹 Bridge Pattern</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*_zBTtQRfTuNpD3Ba.jpeg" /><figcaption>Structure Design patterns</figcaption></figure><h3>Today we’ll cover first 2 patterns:</h3><ol><li><strong>Adapter Pattern</strong></li><li><strong>Facade Pattern</strong></li></ol><h3>1. Adapter Pattern</h3><h3>Definition:</h3><p>Adapter Pattern <strong>converts the interface</strong> of a class into <strong>another interface</strong> that a client expects.<br>It <strong>“adapts”</strong> one interface to another so that incompatible classes can work together.</p><h3>When to Use Adapter?</h3><p>✅ You have <strong>existing code</strong> (legacy classes) and you <strong>can’t change it</strong>, but you need it to work with <strong>new systems</strong>.<br>✅ You want to <strong>reuse</strong> a class without modifying it.</p><h3>Real-Life Example:</h3><p><strong>Charger Adapter:</strong></p><ul><li>Your laptop uses a USB-C charger.</li><li>You have an old charger that is only USB-A.</li><li>You use a <strong>USB-A to USB-C adapter</strong> to make it compatible.</li></ul><h3>Example Code: (Java)</h3><p>Suppose we have an old MediaPlayer that only plays .mp3, but now we need .mp4 support too.</p><pre>// Existing media player<br>interface MediaPlayer {<br>    void play(String audioType, String fileName);<br>}<br><br>// Advanced media player (new functionality)<br>interface AdvancedMediaPlayer {<br>    void playVlc(String fileName);<br>    void playMp4(String fileName);<br>}<br>// Concrete implementation for MP4<br>class Mp4Player implements AdvancedMediaPlayer {<br>    public void playVlc(String fileName) {}<br>    public void playMp4(String fileName) {<br>        System.out.println(&quot;Playing mp4 file. Name: &quot; + fileName);<br>    }<br>}<br>// Adapter Class<br>class MediaAdapter implements MediaPlayer {<br>    AdvancedMediaPlayer advancedMusicPlayer;<br>    MediaAdapter(String audioType){<br>        if(audioType.equalsIgnoreCase(&quot;mp4&quot;)){<br>            advancedMusicPlayer = new Mp4Player();<br>        }<br>    }<br>    public void play(String audioType, String fileName) {<br>        if(audioType.equalsIgnoreCase(&quot;mp4&quot;)){<br>            advancedMusicPlayer.playMp4(fileName);<br>        }<br>    }<br>}<br>// Audio player using adapter<br>class AudioPlayer implements MediaPlayer {<br>    MediaAdapter mediaAdapter;<br>    public void play(String audioType, String fileName) {<br>        if(audioType.equalsIgnoreCase(&quot;mp3&quot;)){<br>            System.out.println(&quot;Playing mp3 file. Name: &quot; + fileName);<br>        } else if(audioType.equalsIgnoreCase(&quot;mp4&quot;)){<br>            mediaAdapter = new MediaAdapter(audioType);<br>            mediaAdapter.play(audioType, fileName);<br>        }<br>    }<br>}</pre><p>✅ Now AudioPlayer can handle both mp3 and mp4!</p><h3>Diagram: Adapter Pattern</h3><pre>Client -&gt; Target Interface (MediaPlayer)<br>                  ↓<br>            Adapter (MediaAdapter)<br>                  ↓<br>    Adaptee (AdvancedMediaPlayer)</pre><h3>2. Facade Pattern</h3><h3>Definition:</h3><p>Facade Pattern provides a <strong>simple interface</strong> to a <strong>complex subsystem</strong> of classes.<br> It hides the complexity and provides a <strong>higher-level interface</strong>.</p><h3>When to Use Facade?</h3><p>✅ A system is <strong>very complex or difficult to understand</strong> for new users.<br>✅ You want to <strong>organize a complex system</strong> into <strong>subsystems</strong>.</p><h3>Real-Life Example:</h3><ul><li><strong>Hotel Reception:</strong></li><li>When you check into a hotel, you don’t call housekeeping, catering, room service individually.</li><li><strong>Reception desk</strong> acts as a <strong>facade</strong> and handles everything for you.</li></ul><h3>Example Code: (Java)</h3><p>Imagine a <strong>Home Theater System</strong>: Amplifier, DVD Player, Lights, Projector…</p><pre>class Amplifier {<br>    void on() { System.out.println(&quot;Amplifier ON&quot;); }<br>    void off() { System.out.println(&quot;Amplifier OFF&quot;); }<br>}<br>class DVDPlayer {<br>    void on() { System.out.println(&quot;DVD Player ON&quot;); }<br>    void play(String movie) { System.out.println(&quot;Playing movie: &quot; + movie); }<br>    void off() { System.out.println(&quot;DVD Player OFF&quot;); }<br>}<br>class Lights {<br>    void dim() { System.out.println(&quot;Lights dimmed&quot;); }<br>}<br>// Facade class<br>class HomeTheaterFacade {<br>    private Amplifier amp;<br>    private DVDPlayer dvd;<br>    private Lights lights;<br>    public HomeTheaterFacade(Amplifier amp, DVDPlayer dvd, Lights lights) {<br>        this.amp = amp;<br>        this.dvd = dvd;<br>        this.lights = lights;<br>    }<br>    public void watchMovie(String movie) {<br>        System.out.println(&quot;Get ready to watch a movie...&quot;);<br>        lights.dim();<br>        amp.on();<br>        dvd.on();<br>        dvd.play(movie);<br>    }<br>    public void endMovie() {<br>        System.out.println(&quot;Shutting movie theater down...&quot;);<br>        dvd.off();<br>        amp.off();<br>    }<br>}</pre><p>✅ Now, <strong>one method call</strong> (watchMovie()) starts the <strong>entire complex subsystem</strong>!</p><h3>Diagram: Facade Pattern</h3><pre>Client -&gt; Facade (HomeTheaterFacade)<br>                  ↓<br>   Subsystems (Amplifier, DVDPlayer, Lights)</pre><h3>Quick Summary</h3><p>Pattern Purpose Example <strong>Adapter</strong> Make <strong>incompatible interfaces</strong> work together Charger adapter, media player <strong>Facade</strong> <strong>Simplify complex systems</strong> behind a single interface Hotel reception, Home Theater</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9533dd98cf5d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When to Use Each Creational Pattern? (Use Cases & Decision Guide)]]></title>
            <link>https://medium.com/@atuljaiss7/when-to-use-each-creational-pattern-use-cases-decision-guide-0c8e318234fb?source=rss-18eb19ebb450------2</link>
            <guid isPermaLink="false">https://medium.com/p/0c8e318234fb</guid>
            <category><![CDATA[low-level-design]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[creational-design-pattern]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[Atuljaiss]]></dc:creator>
            <pubDate>Sun, 09 Mar 2025 06:52:27 GMT</pubDate>
            <atom:updated>2025-03-09T06:52:27.719Z</atom:updated>
            <content:encoded><![CDATA[<p>Each <strong>Creational Pattern</strong> is designed for specific scenarios. Let’s analyze <strong>where to use them</strong> and <strong>how to decide the right one</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*stqoLp0LViCmUWwwAapNPQ.png" /></figure><h3>🔹 Factory Pattern — When to Use?</h3><p>✅ <strong>Use Factory Pattern when:</strong><br> You <strong>don’t want clients</strong> to worry about object creation logic.<br> You have a <strong>common interface</strong> but need different implementations dynamically.<br> The exact type of object is <strong>determined at runtime</strong>.</p><p>💡 <strong>Real-Life Example:</strong><br>Payment Processing System → The system dynamically decides whether to use <strong>CreditCardPayment</strong>, <strong>UPIPayment</strong>, or <strong>PayPalPayment</strong>.</p><p>💻 <strong>Example Use Case in Code:</strong></p><pre>Payment payment = PaymentFactory.getPayment(&quot;UPI&quot;);<br>payment.processPayment();</pre><p>✅ <strong>Good for:</strong></p><ul><li>Payment gateways</li><li>Database connections (MySQL, PostgreSQL, MongoDB)</li><li>Notification services (Email, SMS, Push)</li></ul><p>❌ <strong>Don’t use when:</strong></p><ul><li>You have only <strong>one class</strong> (no variations).</li><li>Object creation is <strong>not complex</strong> (direct instantiation is enough).</li></ul><h3>🔹 Singleton Pattern — When to Use?</h3><p>✅ <strong>Use Singleton Pattern when:</strong><br> You need <strong>only one instance</strong> of a class.<br> Multiple parts of the application <strong>share the same state</strong>.<br> Object creation is <strong>expensive</strong>, and multiple instances would be inefficient.</p><p>💡 <strong>Real-Life Example:</strong><br><strong>Database Connection Pool</strong> → A single instance of the DB connection manager ensures all queries use the <strong>same connection</strong>.</p><p>💻 <strong>Example Use Case in Code:</strong></p><pre>SingletonLogger logger = SingletonLogger.getInstance();<br>logger.log(&quot;This is a log message&quot;);</pre><p>✅ <strong>Good for:</strong></p><ul><li>Configuration managers</li><li>Caching mechanisms</li><li>Loggers</li><li>Thread pools</li></ul><p>❌ <strong>Don’t use when:</strong></p><ul><li>You need <strong>multiple independent objects</strong>.</li><li>The class does <strong>not share state globally</strong>.</li></ul><h3>🔹 Builder Pattern — When to Use?</h3><p>✅ <strong>Use Builder Pattern when:</strong><br> An object has <strong>many optional parameters</strong>.<br> Multiple configurations of an object exist.<br> You want to avoid <strong>constructor overloads</strong>.</p><p>💡 <strong>Real-Life Example:</strong><br><strong>Hotel Booking System</strong> → A user may or may not include <strong>Wi-Fi, breakfast, airport pickup</strong>. Instead of creating multiple constructors, we <strong>build the object step-by-step</strong>.</p><p>💻 <strong>Example Use Case in Code:</strong></p><pre>House house = new House.HouseBuilder()<br>    .setRooms(4)<br>    .setGarage(true)<br>    .setGarden(false)<br>    .build();</pre><p>✅ <strong>Good for:</strong></p><ul><li>Complex objects with <strong>optional parameters</strong></li><li>Configurable UI components</li><li>API request builders</li></ul><p>❌ <strong>Don’t use when:</strong></p><ul><li>The object <strong>doesn’t have many optional parameters</strong>.</li><li>A <strong>simple constructor</strong> is enough.</li></ul><h3>🔹 Prototype Pattern — When to Use?</h3><p>✅ <strong>Use Prototype Pattern when:</strong><br> Object creation is <strong>expensive</strong> (e.g., requires database calls).<br> You need <strong>multiple copies</strong> of an existing object.<br> You want to create <strong>new instances from a template</strong>.</p><p>💡 <strong>Real-Life Example:</strong><br><strong>Game Character Templates</strong> → Instead of <strong>creating</strong> each character from scratch, the game clones an existing character <strong>and modifies</strong> attributes like name, weapon, or skills.</p><p>💻 <strong>Example Use Case in Code:</strong></p><pre>Employee emp2 = emp1.clone();<br>emp2.setName(&quot;Bob&quot;);</pre><p>✅ <strong>Good for:</strong></p><ul><li>Cloning objects in <strong>large datasets</strong></li><li>Copy-paste features</li><li>Creating similar objects <strong>with minor modifications</strong></li></ul><p>❌ <strong>Don’t use when:</strong></p><ul><li>Object creation is <strong>not expensive</strong>.</li><li>Objects <strong>don’t require cloning</strong>.</li></ul><h3>📌 Final Takeaway</h3><p><strong>Factory</strong> → When you need <strong>dynamic object creation</strong><br> <strong>Singleton</strong> → When you need <strong>one instance globally</strong><br> <strong>Builder</strong> → When you have <strong>too many optional parameters</strong><br> <strong>Prototype</strong> → When you need <strong>efficient cloning</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0c8e318234fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What Are Design Patterns?]]></title>
            <link>https://medium.com/@atuljaiss7/what-are-design-patterns-3eec362775b6?source=rss-18eb19ebb450------2</link>
            <guid isPermaLink="false">https://medium.com/p/3eec362775b6</guid>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[creational-design-pattern]]></category>
            <category><![CDATA[low-level-design]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Atuljaiss]]></dc:creator>
            <pubDate>Sat, 08 Mar 2025 16:42:55 GMT</pubDate>
            <atom:updated>2025-03-08T16:42:55.695Z</atom:updated>
            <content:encoded><![CDATA[<h3>Design Patterns</h3><p>Design patterns are <strong>proven solutions</strong> to recurring problems in software design. They help create <strong>scalable, maintainable, and flexible</strong> applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rAlP_R2nS4sqwMFn.png" /></figure><p>These patterns are categorized into <strong>three types</strong>:</p><h3>1️⃣ Creational Patterns — Object creation mechanisms</h3><p>🔹 Factory Pattern<br> 🔹 Singleton Pattern<br> 🔹 Builder Pattern<br> 🔹 Prototype Pattern</p><h3>2️⃣ Structural Patterns — Class &amp; object composition</h3><p>🔹 Adapter Pattern<br> 🔹 Decorator Pattern<br> 🔹 Composite Pattern<br> 🔹 Facade Pattern</p><h3>3️⃣ Behavioral Patterns — Communication between objects</h3><p>🔹 Observer Pattern<br> 🔹 Strategy Pattern<br> 🔹 Command Pattern<br> 🔹 Chain of Responsibility</p><h3>Creational Design Patterns</h3><p>Creational patterns focus on <strong>how objects are created</strong> while ensuring <strong>flexibility and reusability</strong>. These patterns help avoid <strong>tight coupling</strong> and make object creation <strong>more efficient</strong>.</p><h3>Types of Creational Patterns:</h3><p>1️⃣ <strong>Factory Pattern</strong> — Creates objects without specifying exact class<br> 2️⃣ <strong>Singleton Pattern</strong> — Ensures a single instance of a class<br> 3️⃣ <strong>Builder Pattern</strong> — Step-by-step object creation<br> 4️⃣ <strong>Prototype Pattern</strong> — Clones existing objects</p><h3>1️⃣ Factory Pattern (Object Creation Without Exposing Class)</h3><p>🔹 <strong>Problem:</strong> When you need to create an object <strong>without specifying the exact class</strong>.<br> 🔹 <strong>Solution:</strong> Factory <strong>hides the object creation logic</strong> and returns an appropriate instance.</p><h3>🔹 Real-Life Example:</h3><p>A <strong>food delivery app</strong> has multiple restaurants. When you place an order, the app <strong>decides which restaurant</strong> to pick based on your location and availability.</p><h3>🔹 Code Example (Factory Pattern — Java)</h3><pre>// Step 1: Create an interface<br>interface Vehicle {<br>    void drive();<br>}<br><br>// Step 2: Implement concrete classes<br>class Car implements Vehicle {<br>    public void drive() {<br>        System.out.println(&quot;Driving a Car&quot;);<br>    }<br>}<br>class Bike implements Vehicle {<br>    public void drive() {<br>        System.out.println(&quot;Riding a Bike&quot;);<br>    }<br>}<br>// Step 3: Create Factory class<br>class VehicleFactory {<br>    public static Vehicle getVehicle(String type) {<br>        if (type.equalsIgnoreCase(&quot;Car&quot;)) {<br>            return new Car();<br>        } else if (type.equalsIgnoreCase(&quot;Bike&quot;)) {<br>            return new Bike();<br>        }<br>        return null;<br>    }<br>}<br>// Step 4: Use Factory in Main Method<br>public class Main {<br>    public static void main(String[] args) {<br>        Vehicle myVehicle = VehicleFactory.getVehicle(&quot;Car&quot;);<br>        myVehicle.drive();  // Output: Driving a Car<br>    }<br>}</pre><p>✅ <strong>Benefits:</strong></p><ul><li><strong>Loose coupling</strong> (client doesn’t directly create objects)</li><li><strong>Easier to extend</strong> (just add new classes without modifying existing code)</li></ul><h3>2️⃣ Singleton Pattern (Only One Instance)</h3><p>🔹 <strong>Problem:</strong> Ensure that <strong>only one instance</strong> of a class exists in the entire application.<br> 🔹 <strong>Solution:</strong> Restrict object creation and provide <strong>a global access point</strong>.</p><h3>🔹 Real-Life Example:</h3><ul><li><strong>Logger</strong> (only one instance should write logs)</li><li><strong>Database connection</strong> (one shared connection pool)</li><li><strong>Configuration manager</strong> (single source for app settings)</li></ul><h3>🔹 Code Example (Singleton Pattern — Java)</h3><pre>class Singleton {<br>    private static Singleton instance; // Single instance<br><br>    private Singleton() { } // Private constructor<br>    public static Singleton getInstance() {<br>        if (instance == null) {<br>            instance = new Singleton();  // Lazy initialization<br>        }<br>        return instance;<br>    }<br>    public void showMessage() {<br>        System.out.println(&quot;Singleton Instance&quot;);<br>    }<br>}<br>public class Main {<br>    public static void main(String[] args) {<br>        Singleton obj1 = Singleton.getInstance();<br>        Singleton obj2 = Singleton.getInstance();<br>        obj1.showMessage();<br>        <br>        System.out.println(obj1 == obj2);  // Output: true (Both are same instance)<br>    }<br>}</pre><p>✅ <strong>Benefits:</strong></p><ul><li><strong>Ensures only one instance</strong></li><li><strong>Saves memory</strong> (no duplicate objects)</li><li><strong>Useful for shared resources</strong></li></ul><h3>3️⃣ Builder Pattern (Step-by-Step Object Creation)</h3><p>🔹 <strong>Problem:</strong> When an object has <strong>too many parameters</strong>, the constructor becomes <strong>hard to manage</strong>.<br> 🔹 <strong>Solution:</strong> The Builder pattern <strong>separates object creation from its representation</strong>.</p><h3>🔹 Real-Life Example:</h3><p>When booking a <strong>hotel room</strong>, you can specify <strong>optional parameters</strong> like Wi-Fi, breakfast, pool access, etc.</p><h3>🔹 Code Example (Builder Pattern — Java)</h3><pre>class House {<br>    private int rooms;<br>    private boolean hasGarage;<br>    private boolean hasGarden;<br><br>    private House(HouseBuilder builder) {<br>        this.rooms = builder.rooms;<br>        this.hasGarage = builder.hasGarage;<br>        this.hasGarden = builder.hasGarden;<br>    }<br>    public void showHouse() {<br>        System.out.println(&quot;Rooms: &quot; + rooms + &quot;, Garage: &quot; + hasGarage + &quot;, Garden: &quot; + hasGarden);<br>    }<br>    // Builder Class<br>    static class HouseBuilder {<br>        private int rooms;<br>        private boolean hasGarage;<br>        private boolean hasGarden;<br>        public HouseBuilder setRooms(int rooms) {<br>            this.rooms = rooms;<br>            return this;<br>        }<br>        public HouseBuilder setGarage(boolean hasGarage) {<br>            this.hasGarage = hasGarage;<br>            return this;<br>        }<br>        public HouseBuilder setGarden(boolean hasGarden) {<br>            this.hasGarden = hasGarden;<br>            return this;<br>        }<br>        public House build() {<br>            return new House(this);<br>        }<br>    }<br>}<br>public class Main {<br>    public static void main(String[] args) {<br>        House myHouse = new House.HouseBuilder()<br>                .setRooms(3)<br>                .setGarage(true)<br>                .setGarden(false)<br>                .build();<br>        myHouse.showHouse();<br>    }<br>}</pre><p>✅ <strong>Benefits:</strong></p><ul><li><strong>Easier to create complex objects</strong></li><li><strong>Readable code</strong> (no long constructor chains)</li><li><strong>Flexible customization</strong></li></ul><h3>4️⃣ Prototype Pattern (Clone Objects)</h3><p>🔹 <strong>Problem:</strong> Creating new objects is <strong>expensive</strong> (e.g., copying large data).<br> 🔹 <strong>Solution:</strong> Instead of <strong>creating a new object</strong>, we <strong>clone an existing one</strong>.</p><h3>🔹 Real-Life Example:</h3><ul><li><strong>Copy-Paste feature</strong> in apps</li><li><strong>Game character templates</strong> (instead of re-creating each character)</li></ul><h3>🔹 Code Example (Prototype Pattern — Java)</h3><pre>class Employee implements Cloneable {<br>    String name;<br>    String position;<br><br>    Employee(String name, String position) {<br>        this.name = name;<br>        this.position = position;<br>    }<br>    public Employee clone() throws CloneNotSupportedException {<br>        return (Employee) super.clone();<br>    }<br>    public void showInfo() {<br>        System.out.println(&quot;Name: &quot; + name + &quot;, Position: &quot; + position);<br>    }<br>}<br>public class Main {<br>    public static void main(String[] args) throws CloneNotSupportedException {<br>        Employee emp1 = new Employee(&quot;Alice&quot;, &quot;Developer&quot;);<br>        Employee emp2 = emp1.clone(); // Clone existing employee<br>        emp2.name = &quot;Bob&quot;;  // Modify cloned object<br>        emp1.showInfo();  // Output: Name: Alice, Position: Developer<br>        emp2.showInfo();  // Output: Name: Bob, Position: Developer<br>    }<br>}</pre><p>✅ <strong>Benefits:</strong></p><ul><li><strong>Faster object creation</strong> (no re-initialization)</li><li><strong>Saves memory</strong> (reuses existing data)</li></ul><h3>📌 Summary of Creational Patterns</h3><p>Pattern Purpose Example <strong>Factory</strong> Create objects <strong>without specifying exact class</strong> Choosing a <strong>Car</strong> or <strong>Bike</strong> dynamically <strong>Singleton</strong> Only <strong>one instance</strong> exists globally Database connection, Logger <strong>Builder</strong> <strong>Step-by-step object creation</strong> Building a <strong>House</strong> with different options <strong>Prototype</strong> <strong>Clone existing objects</strong> Copying an <strong>Employee object.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3eec362775b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Software Engineering Principles: DRY, KISS, YAGNI]]></title>
            <link>https://medium.com/@atuljaiss7/software-engineering-principles-dry-kiss-yagni-7df5243cfc8e?source=rss-18eb19ebb450------2</link>
            <guid isPermaLink="false">https://medium.com/p/7df5243cfc8e</guid>
            <category><![CDATA[dry]]></category>
            <category><![CDATA[kiss]]></category>
            <category><![CDATA[low-level-design]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[yagni]]></category>
            <dc:creator><![CDATA[Atuljaiss]]></dc:creator>
            <pubDate>Thu, 06 Mar 2025 15:45:10 GMT</pubDate>
            <atom:updated>2025-03-06T15:45:10.130Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yIs_5CyPIPpr2XcsfDoNyw.png" /></figure><p><strong>1. DRY (Don’t Repeat Yourself)</strong></p><p><strong>Concept:</strong></p><ul><li>This principle is about avoiding code duplication. If you find yourself writing the same code over and over again, you should create a function or class to encapsulate that code. This will make your code more maintainable and less error-prone.</li><li>Repeating code leads to maintenance nightmares. If you need to change something, you have to find and modify it in multiple places, increasing the risk of errors.</li><li>For example, suppose you have a function that is used to calculate the area of a circle. You might write the same function several times in your code. Instead, you should create a single function that can be used to calculate the area of a circle. This will make your code more maintainable and less error-prone.</li></ul><pre>// Bad (Repeating code)<br>public class CircleCalculatorBad {<br>    public double calculateArea(double radius) {<br>        return 3.14159 * radius * radius;<br>    }<br><br>    public double calculateCircumference(double radius) {<br>        return 2 * 3.14159 * radius;<br>    }<br>}<br><br>// Good (Using a constant)<br>public class CircleCalculatorGood {<br>    private static final double PI = 3.14159;<br><br>    public double calculateArea(double radius) {<br>        return PI * radius * radius;<br>    }<br><br>    public double calculateCircumference(double radius) {<br>        return 2 * PI * radius;<br>    }<br>}</pre><ul><li>The “Good” example uses a constant PI to avoid repeating the value.</li><li>If PI needs to change, it&#39;s modified in one place.</li><li>Functions contain the logic, and are reused.</li></ul><p><strong>2. KISS (Keep It Simple, Stupid)</strong></p><p><strong>Concept:</strong></p><ul><li>This principle is about writing code that is easy to understand and maintain. It is often summarised as “keep it simple, stupid.” This means that you should avoid writing code that is too complex or difficult to understand. Instead, you should focus on writing code that is clear, concise, and easy to follow.</li><li>For example, suppose you have a function that is used to calculate the area of a circle. You might write the function in a very complex way, using a lot of nested loops and conditional statements. However, you can write the same function in a much simpler way, using a single loop and a few conditional statements. This will make your code easier to understand and maintain.</li></ul><pre>// Bad (Overly complex)<br>public class EvenCheckerBad {<br>    public boolean isEven(int number) {<br>        if (number % 2 == 0) {<br>            return true;<br>        } else {<br>            return false;<br>        }<br>    }<br>}<br><br>// Good (Simple and direct)<br>public class EvenCheckerGood {<br>    public boolean isEven(int number) {<br>        return number % 2 == 0;<br>    }<br>}</pre><ul><li>The “Good” example directly returns the result of the modulo operation, making it concise.</li><li>The “Bad” example is longer, and harder to read.</li><li>Simple code reduces the risk of bugs.</li></ul><p><strong>3. YAGNI (You Ain’t Gonna Need It)</strong></p><p><strong>Concept:</strong></p><ul><li>This principle is about not writing code that you don’t need right now. It is often tempting to write code that you think you might need in the future, but this can lead to wasted time and effort. Instead, you should focus on writing the code that you need right now. If you need to add additional functionality later, you can always do that then.</li><li>For example, suppose you are writing a web application. You might be tempted to write code that will handle all of the possible HTTP requests that the application could receive. However, you should only write the code that you need to handle the requests that the application is currently receiving. If you need to handle additional requests in the future, you can always add that code then.</li></ul><p><strong>Example :</strong></p><p>You’re building a basic user management system. <br>“Bad” approach: You immediately implement advanced features like user roles, permissions, and audit trails, even though you only need basic user creation and login initially.<br>“Good” approach: Start with the essential user creation and login functionality. Add roles, permissions, and audit trails only when they become necessary.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7df5243cfc8e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SOLID Principles — The Foundation of Good Design]]></title>
            <link>https://medium.com/@atuljaiss7/solid-principles-the-foundation-of-good-design-e88ce74ff431?source=rss-18eb19ebb450------2</link>
            <guid isPermaLink="false">https://medium.com/p/e88ce74ff431</guid>
            <category><![CDATA[low-level-design]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[solid-principles]]></category>
            <dc:creator><![CDATA[Atuljaiss]]></dc:creator>
            <pubDate>Sun, 02 Mar 2025 11:04:31 GMT</pubDate>
            <atom:updated>2025-03-05T12:28:34.000Z</atom:updated>
            <content:encoded><![CDATA[<h3>SOLID Principles — The Foundation of Good Design</h3><p>The <strong>SOLID principles</strong> are five design principles that help developers write clean, scalable, and maintainable code. These principles were introduced by <strong>Robert C. Martin (Uncle Bob)</strong> and form the foundation of <strong>Low-Level Design (LLD)</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/0*fk3PClPfyz6RWLK7.png" /></figure><h3>1️⃣ S — Single Responsibility Principle (SRP)</h3><p><strong>“A class should have only one reason to change.”</strong></p><p>🔹 <strong>What does it mean?</strong><br> A class should have only <strong>one responsibility</strong>, meaning it should only perform <strong>one function or job</strong>.</p><p>🔹 <strong>Real-Life Example:</strong><br> A <strong>restaurant</strong> has different roles:</p><ul><li>The <strong>Chef</strong> cooks food</li><li>The <strong>Waiter</strong> takes orders</li><li>The <strong>Cashier</strong> handles billing</li></ul><p>Each role has a single responsibility. If a <strong>Waiter</strong> also starts cooking, the system becomes messy!</p><p>🔹 <strong>Bad Example (Violating SRP)</strong></p><pre>class Invoice {<br>    void calculateTotal() { /* logic to calculate total */ }<br>    void printInvoice() { /* logic to print invoice */ }<br>    void saveToDatabase() { /* logic to save invoice to DB */ }<br>}</pre><p>🚨 <strong>Problem:</strong><br> This class has <strong>three responsibilities</strong> — calculation, printing, and database operations.</p><p>🔹 <strong>Corrected Example (Following SRP)</strong></p><pre>class Invoice {<br>    void calculateTotal() { /* logic to calculate total */ }<br>}<br>class InvoicePrinter {<br>    void printInvoice(Invoice invoice) { /* logic to print invoice */ }<br>}<br>class InvoiceRepository {<br>    void saveToDatabase(Invoice invoice) { /* logic to save invoice to DB */ }<br>}</pre><p>✅ <strong>Now, each class has a single responsibility.</strong></p><h3>2️⃣ O — Open/Closed Principle (OCP)</h3><p><strong>“A class should be open for extension but closed for modification.”</strong></p><p>🔹 <strong>What does it mean?</strong><br> You should be able to add new functionality <strong>without modifying existing code</strong>.</p><p>🔹 <strong>Real-Life Example:</strong><br> A <strong>mobile charger</strong> works with different plug types using an <strong>adapter</strong>. Instead of modifying the charger, we just create new adapters for different plugs.</p><p>🔹 <strong>Bad Example (Violating OCP)</strong></p><pre>class Payment {<br>    void processPayment(String type) {<br>        if (type.equals(&quot;CreditCard&quot;)) {<br>            // Credit Card payment logic<br>        } else if (type.equals(&quot;UPI&quot;)) {<br>            // UPI payment logic<br>        }<br>    }<br>}</pre><p>🚨 <strong>Problem:</strong><br> Every time a new payment method is added, we need to modify the class.</p><p>🔹 <strong>Corrected Example (Following OCP using Polymorphism)</strong></p><pre>interface Payment {<br>    void processPayment();<br>}<br><br>class CreditCardPayment implements Payment {<br>    public void processPayment() { System.out.println(&quot;Processing Credit Card Payment&quot;); }<br>}<br>class UPIPayment implements Payment {<br>    public void processPayment() { System.out.println(&quot;Processing UPI Payment&quot;); }<br>}<br>class PaymentProcessor {<br>    void process(Payment payment) {<br>        payment.processPayment();<br>    }<br>}</pre><p>✅ <strong>Now, to add a new payment method (e.g., PayPal), we just create a new class without modifying existing ones!</strong></p><h3>3️⃣ L — Liskov Substitution Principle (LSP)</h3><p><strong>“A subclass should be replaceable by its parent class without breaking functionality.”</strong></p><p>🔹 <strong>What does it mean?</strong><br> A subclass should extend the parent class without changing its behavior.</p><p>🔹 <strong>Real-Life Example:</strong><br> A <strong>Penguin</strong> is a type of <strong>Bird</strong>, but it <strong>can’t fly</strong>. If our Bird class has a fly() method and we substitute it with Penguin, it will break the logic.</p><p>🔹 <strong>Bad Example (Violating LSP)</strong></p><pre>class Bird {<br>    void fly() { System.out.println(&quot;Flying&quot;); }<br>}<br><br>class Penguin extends Bird { }  // Penguins can&#39;t fly, but inherit fly()!</pre><p>🚨 <strong>Problem:</strong><br> Penguin.fly() will give incorrect behavior.</p><p>🔹 <strong>Corrected Example (Following LSP using Interfaces)</strong></p><pre>interface Bird { void eat(); }<br><br>interface FlyingBird extends Bird { void fly(); }<br><br><br>class Sparrow implements FlyingBird {<br>    public void eat() { System.out.println(&quot;Sparrow eating&quot;); }<br>    public void fly() { System.out.println(&quot;Sparrow flying&quot;); }<br>}<br>class Penguin implements Bird {<br>    public void eat() { System.out.println(&quot;Penguin eating&quot;); }<br>}</pre><p>✅ <strong>Now, Penguin doesn’t inherit </strong><strong>fly(), avoiding incorrect behavior.</strong></p><h3>4️⃣ I — Interface Segregation Principle (ISP)</h3><p><strong>“Clients should not be forced to depend on interfaces they don’t use.”</strong></p><p>🔹 <strong>What does it mean?</strong><br> A class should only implement the methods it needs. Large interfaces should be <strong>split into smaller, specific interfaces</strong>.</p><p>🔹 <strong>Real-Life Example:</strong><br> A <strong>printer</strong> can <strong>print</strong>, <strong>scan</strong>, and <strong>fax</strong>. But a <strong>simple printer</strong> doesn’t need <strong>scan</strong> and <strong>fax</strong> functionalities.</p><p>🔹 <strong>Bad Example (Violating ISP)</strong></p><pre>interface Printer {<br>    void print();<br>    void scan();<br>    void fax();<br>}<br><br>class BasicPrinter implements Printer {<br>    public void print() { System.out.println(&quot;Printing...&quot;); }<br>    public void scan() { throw new UnsupportedOperationException(&quot;Not supported!&quot;); }<br>    public void fax() { throw new UnsupportedOperationException(&quot;Not supported!&quot;); }<br>}</pre><p>🚨 <strong>Problem:</strong><br> BasicPrinter is forced to implement scan() and fax(), which it doesn&#39;t support.</p><p>🔹 <strong>Corrected Example (Following ISP by creating separate interfaces)</strong></p><pre>interface Printer {<br>    void print();<br>}<br><br>interface Scanner {<br>    void scan();<br>}<br><br>interface Fax {<br>    void fax();<br>}<br><br>class BasicPrinter implements Printer {<br>    public void print() { System.out.println(&quot;Printing...&quot;); }<br>}<br><br>class AdvancedPrinter implements Printer, Scanner, Fax {<br>    public void print() { System.out.println(&quot;Printing...&quot;); }<br>    public void scan() { System.out.println(&quot;Scanning...&quot;); }<br>    public void fax() { System.out.println(&quot;Faxing...&quot;); }<br>}</pre><p>✅ <strong>Now, a basic printer only implements the required functionality.</strong></p><h3>5️⃣ D — Dependency Inversion Principle (DIP)</h3><p><strong>“High-level modules should not depend on low-level modules. Both should depend on abstractions.”</strong></p><p>🔹 <strong>What does it mean?</strong><br> Instead of a class directly creating objects of another class, <strong>it should depend on an interface or abstraction</strong> so that we can switch implementations easily.</p><p>🔹 <strong>Real-Life Example:</strong><br> A <strong>computer</strong> can use different types of keyboards (wired, wireless). The computer doesn’t depend on a specific keyboard type, just on an abstract <strong>Keyboard interface</strong>.</p><p>🔹 <strong>Bad Example (Violating DIP)</strong></p><pre>class WiredKeyboard {<br>    void type() { System.out.println(&quot;Typing on Wired Keyboard&quot;); }<br>}<br><br>class Computer {<br>    private WiredKeyboard keyboard = new WiredKeyboard();  // Direct dependency<br>    void useKeyboard() { keyboard.type(); }<br>}</pre><p>🚨 <strong>Problem:</strong><br> If we want to use a <strong>WirelessKeyboard</strong>, we must modify Computer, violating OCP.</p><p>🔹 <strong>Corrected Example (Following DIP using Abstraction)</strong></p><pre>interface Keyboard {<br>    void type();<br>}<br><br>class WiredKeyboard implements Keyboard {<br>    public void type() { System.out.println(&quot;Typing on Wired Keyboard&quot;); }<br>}<br><br>class WirelessKeyboard implements Keyboard {<br>    public void type() { System.out.println(&quot;Typing on Wireless Keyboard&quot;); }<br>}<br><br>class Computer {<br>    private Keyboard keyboard;<br>    Computer(Keyboard keyboard) { this.keyboard = keyboard; }<br>    void useKeyboard() { keyboard.type(); }<br>}<br><br>public class Main {<br>    public static void main(String[] args) {<br>        Keyboard myKeyboard = new WirelessKeyboard();<br>        Computer myComputer = new Computer(myKeyboard);<br>        myComputer.useKeyboard();<br>    }<br>}</pre><p>✅ <strong>Now, we can switch keyboards without modifying the </strong><strong>Computer class!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e88ce74ff431" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Object-Oriented Programming (OOP) — Detailed Explanation]]></title>
            <link>https://medium.com/@atuljaiss7/object-oriented-programming-oop-detailed-explanation-e1ff3a5cd7ca?source=rss-18eb19ebb450------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1ff3a5cd7ca</guid>
            <category><![CDATA[object-oriented-concepts]]></category>
            <category><![CDATA[low-level-design]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Atuljaiss]]></dc:creator>
            <pubDate>Sun, 02 Mar 2025 10:17:28 GMT</pubDate>
            <atom:updated>2025-03-04T03:22:51.471Z</atom:updated>
            <content:encoded><![CDATA[<h3>Object-Oriented Programming (OOP) — Detailed Explanation</h3><p>Object-Oriented Programming (OOP) is a programming paradigm based on the concept of <strong>objects</strong>, which contain both <strong>data (attributes)</strong> and <strong>behavior (methods)</strong>. It allows for code reuse, scalability, and maintainability.</p><h3>1️⃣ Four Pillars of OOP</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*2vHwA251bYvpV2hYjrwjxQ.png" /><figcaption>Pillars of Oops</figcaption></figure><h3>1. Encapsulation (Data Hiding)</h3><p>Encapsulation means bundling the <strong>data (variables)</strong> and <strong>methods (functions)</strong> into a single unit (class) and restricting direct access to some details.</p><p>🔹 <strong>Real-Life Example:</strong><br> A <strong>car</strong> has an <strong>engine</strong> inside it, but as a driver, you don’t need to directly access or modify the engine’s internals. You only interact with the <strong>steering, accelerator, and brakes</strong>.</p><p>🔹 <strong>Code Example (Java)</strong></p><pre>class Car {<br>    private String engine = &quot;V8 Engine&quot;;  // Private variable (hidden)<br>    <br>    public void startCar() {<br>        System.out.println(&quot;Car is starting using &quot; + engine);<br>    }<br>}<br><br>public class Main {<br>    public static void main(String[] args) {<br>        Car myCar = new Car();<br>        myCar.startCar();<br>        // myCar.engine;  // ❌ This would give an error because engine is private<br>    }<br>}</pre><p>✅ Here, the <strong>engine</strong> is private, and access is controlled via a public method.</p><h3>2. Abstraction (Hiding Implementation Details)</h3><p>Abstraction means <strong>hiding complex implementation details</strong> from the user and only exposing necessary functionalities.</p><p>🔹 <strong>Real-Life Example:</strong><br> When you use an <strong>ATM</strong>, you just enter your PIN and amount, and the machine dispenses cash. You don’t see the backend logic of money verification and database updates.</p><p>🔹 <strong>Code Example (Java)</strong></p><pre>abstract class ATM {<br>    abstract void withdrawMoney(int amount);  // Abstract method (no implementation)<br>    <br>    void showBalance() {  // Concrete method (has implementation)<br>        System.out.println(&quot;Showing balance...&quot;);<br>    }<br>}<br>class HDFC_ATM extends ATM {<br>    void withdrawMoney(int amount) {  // Implementation of abstract method<br>        System.out.println(&quot;Withdrawn: &quot; + amount);<br>    }<br>}<br>public class Main {<br>    public static void main(String[] args) {<br>        ATM atm = new HDFC_ATM();<br>        atm.withdrawMoney(5000);<br>        atm.showBalance();<br>    }<br>}</pre><p>✅ The <strong>ATM class</strong> is abstract, meaning it only defines what should be done, but the actual implementation is provided by <strong>HDFC_ATM</strong>.</p><h3>3. Inheritance (Reusability &amp; Hierarchy)</h3><p>Inheritance allows a <strong>child class to inherit properties and behavior</strong> from a <strong>parent class</strong>, reducing code duplication.</p><p>🔹 <strong>Real-Life Example:</strong><br> A <strong>dog</strong> and a <strong>cat</strong> both inherit traits from the <strong>animal</strong> class (like breathing and moving) but also have their own unique behaviors (barking vs. meowing).</p><p>🔹 <strong>Code Example (Java)</strong></p><pre>class Animal {<br>    void eat() {<br>        System.out.println(&quot;This animal eats food.&quot;);<br>    }<br>}<br>class Dog extends Animal {<br>    void bark() {<br>        System.out.println(&quot;Dog barks&quot;);<br>    }<br>}<br>public class Main {<br>    public static void main(String[] args) {<br>        Dog myDog = new Dog();<br>        myDog.eat();  // Inherited method<br>        myDog.bark(); // Dog&#39;s own method<br>    }<br>}</pre><p>✅ The <strong>Dog class</strong> inherits the <strong>eat()</strong> method from the <strong>Animal class</strong> but also defines its own <strong>bark()</strong> method.</p><h3>4. Polymorphism (Multiple Forms)</h3><p>Polymorphism allows objects to be treated as instances of their parent class while behaving differently based on the actual object type.</p><p>🔹 <strong>Real-Life Example:</strong><br> A <strong>single remote control</strong> can operate <strong>multiple devices</strong> like a TV, AC, or Music System, depending on the button pressed.</p><p>🔹 <strong>Code Example (Method Overriding — Java)</strong></p><pre>class Animal {<br>    void makeSound() {<br>        System.out.println(&quot;Animal makes a sound.&quot;);<br>    }<br>}<br>class Dog extends Animal {<br>    void makeSound() {<br>        System.out.println(&quot;Dog barks.&quot;);<br>    }<br>}<br>public class Main {<br>    public static void main(String[] args) {<br>        Animal myAnimal = new Dog();  // Parent class reference, child class object<br>        myAnimal.makeSound();  // Calls Dog&#39;s overridden method<br>    }<br>}</pre><p>✅ Here, even though the reference is of <strong>Animal</strong>, the <strong>Dog’s method</strong> is called because of <strong>runtime polymorphism</strong>.</p><h3>2️⃣ Additional OOP Concepts</h3><h3>Composition (Has-A Relationship)</h3><p>Instead of inheritance, <strong>composition</strong> is used when one class contains another as a part.</p><p>🔹 <strong>Real-Life Example:</strong><br> A <strong>car</strong> has an <strong>engine</strong>. An engine is not a type of car (so we don’t use inheritance), but a car <strong>contains</strong> an engine.</p><p>🔹 <strong>Code Example (Java)</strong></p><pre>class Engine {<br>    void start() {<br>        System.out.println(&quot;Engine started.&quot;);<br>    }<br>}<br>class Car {<br>    private Engine engine;  // Car HAS-A Engine<br>    <br>    Car() {<br>        engine = new Engine();<br>    }<br>    void startCar() {<br>        engine.start();  // Using Engine&#39;s method<br>        System.out.println(&quot;Car is moving.&quot;);<br>    }<br>}<br>public class Main {<br>    public static void main(String[] args) {<br>        Car myCar = new Car();<br>        myCar.startCar();<br>    }<br>}</pre><p>✅ The <strong>Car class</strong> contains an <strong>Engine object</strong> instead of extending an Engine class.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1ff3a5cd7ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Roadmap for Learning Low-Level Design (LLD)]]></title>
            <link>https://medium.com/@atuljaiss7/roadmap-for-learning-low-level-design-lld-dab3ad8f3079?source=rss-18eb19ebb450------2</link>
            <guid isPermaLink="false">https://medium.com/p/dab3ad8f3079</guid>
            <category><![CDATA[design-principles]]></category>
            <category><![CDATA[low-level-programming]]></category>
            <category><![CDATA[solid-principles]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Atuljaiss]]></dc:creator>
            <pubDate>Sun, 02 Mar 2025 10:04:14 GMT</pubDate>
            <atom:updated>2025-03-02T10:04:14.728Z</atom:updated>
            <content:encoded><![CDATA[<p>Low-Level Design (LLD) focuses on implementing detailed class diagrams, object-oriented design principles, and system component interactions to build scalable and maintainable software. Here’s a structured roadmap to master LLD:</p><h3>1️⃣ Core Object-Oriented Programming (OOP) Concepts</h3><p>Before diving into LLD, ensure a strong understanding of:</p><ul><li><strong>Encapsulation</strong></li><li><strong>Abstraction</strong></li><li><strong>Inheritance</strong></li><li><strong>Polymorphism</strong></li></ul><p>📌 <strong>Start with:</strong> “Design Patterns: Elements of Reusable Object-Oriented Software” (Gang of Four — GoF)</p><h3>2️⃣ SOLID Principles</h3><p>These are five key design principles that improve software maintainability and scalability:</p><ul><li><strong>S</strong>: Single Responsibility Principle (SRP)</li><li><strong>O</strong>: Open/Closed Principle (OCP)</li><li><strong>L</strong>: Liskov Substitution Principle (LSP)</li><li><strong>I</strong>: Interface Segregation Principle (ISP)</li><li><strong>D</strong>: Dependency Inversion Principle (DIP)</li></ul><p>📌 <strong>Book Recommendation:</strong> “Clean Code” by Robert C. Martin</p><h3>3️⃣ Design Patterns</h3><p>Common solutions to recurring design problems:</p><ul><li><strong>Creational Patterns</strong> (Factory, Singleton, Builder, Prototype)</li><li><strong>Structural Patterns</strong> (Adapter, Decorator, Composite, Facade)</li><li><strong>Behavioral Patterns</strong> (Observer, Strategy, Command, Chain of Responsibility)</li></ul><p>📌 <strong>Book Recommendation:</strong> “Head First Design Patterns”</p><h3>4️⃣ UML &amp; Class Diagrams</h3><ul><li><strong>Use Case Diagrams</strong></li><li><strong>Class Diagrams</strong></li><li><strong>Sequence Diagrams</strong></li><li><strong>State Machine Diagrams</strong></li></ul><p>📌 <strong>Book Recommendation:</strong> “UML Distilled” by Martin Fowler</p><h3>5️⃣ System Design Components &amp; Low-Level Implementations</h3><ul><li><strong>API Design (REST, GraphQL)</strong></li><li><strong>Database Design (Normalization, Indexing, Transactions)</strong></li><li><strong>Concurrency (Multithreading, Locks, Synchronization)</strong></li><li><strong>Caching Strategies (LRU, LFU, Redis, Memcached)</strong></li><li><strong>Message Queues (Kafka, RabbitMQ)</strong></li></ul><p>📌 <strong>Book Recommendation:</strong> “Designing Data-Intensive Applications” by Martin Kleppmann</p><h3>6️⃣ Case Studies &amp; Real-World Applications</h3><ul><li><strong>Design a Parking Lot</strong></li><li><strong>Design an ATM System</strong></li><li><strong>Design a Library Management System</strong></li><li><strong>Design a Food Delivery App (Zomato/Swiggy)</strong></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dab3ad8f3079" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sorting 5 Billion Integers with Only 8GB RAM — A Step-by-Step Solution]]></title>
            <link>https://medium.com/@atuljaiss7/sorting-5-billion-integers-with-only-8gb-ram-a-step-by-step-solution-dae8df9bc444?source=rss-18eb19ebb450------2</link>
            <guid isPermaLink="false">https://medium.com/p/dae8df9bc444</guid>
            <category><![CDATA[problem-solving]]></category>
            <category><![CDATA[merge-sort]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[memory-improvement]]></category>
            <category><![CDATA[data-structure-algorithm]]></category>
            <dc:creator><![CDATA[Atuljaiss]]></dc:creator>
            <pubDate>Sat, 01 Mar 2025 05:29:23 GMT</pubDate>
            <atom:updated>2025-03-01T05:33:57.231Z</atom:updated>
            <content:encoded><![CDATA[<h3>Sorting 5 Billion Integers with Only 8GB RAM — A Step-by-Step Solution</h3><p><strong>What if you had to sort 5 billion integers coming in as a live stream, but you only had 8GB of RAM but unlimited external storage.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*INFLiRObQNFjgKJvbyYJJA.jpeg" /></figure><p>At first glance, this sounds impossible — trying to load and sort billions of numbers with limited memory feels like an insurmountable challenge. But as I explored the problem, I discovered a powerful technique that makes this not just possible, but surprisingly efficient: <strong>External Merge Sort</strong>.</p><p>Let’s break it down step by step!</p><h3>Understanding the Problem</h3><p><strong>Constraints:</strong></p><ul><li><strong>5 billion integers</strong> (far larger than RAM can handle).</li><li><strong>8GB of RAM</strong> (limited memory).</li><li><strong>Unlimited external storage</strong> (can write to disk as needed).</li><li><strong>Live data stream</strong> (can’t access all data at once).</li></ul><p><strong>Goal:</strong> Sort the entire stream of integers and produce a sorted output.</p><p>Since loading the full dataset into memory is impossible, we need to break the problem into smaller pieces and use disk storage strategically.</p><p>The best approach for this scenario is the <strong>External Merge Sort</strong> algorithm, which sorts chunks of data in memory and then merges them in stages using disk storage.</p><p>Let’s walk through it step by step! 👇</p><h3>Step-by-Step Solution with External Merge Sort</h3><h3>🟩 Step 1: Divide the Stream into Chunks</h3><p>The first step is to <strong>read the incoming stream in fixed-size chunks that fit into RAM</strong>.</p><p>If 8GB of RAM can hold around <strong>100 million integers</strong>, we split the data into chunks of that size.</p><p>🔸 <strong>Example:</strong> For 5 billion integers, we’ll create <strong>50 chunks</strong>, each containing <strong>100 million integers</strong>.</p><h3>🟩 Step 2: Sort Each Chunk in Memory</h3><p>Once a chunk is loaded into memory, <strong>sort it using an efficient in-memory algorithm</strong> like <strong>QuickSort</strong> or <strong>MergeSort</strong>.</p><ul><li><strong>Time Complexity:</strong> O(N log N) for each chunk.</li><li><strong>Why not simpler algorithms?</strong> Faster algorithms like <strong>QuickSort</strong> handle large data more efficiently than naive options (e.g., Bubble Sort).</li></ul><p>After sorting, <strong>write the sorted chunk to disk as a temporary file</strong> (e.g., chunk1, chunk2, chunk3, etc.).</p><h3>🟩 Step 3: Merge the Sorted Chunks (K-Way Merge)</h3><p>Now comes the magic! We need to <strong>merge all the sorted chunks</strong> into a single sorted output.</p><p>The most efficient way to do this is with a <strong>K-Way Merge</strong> using a <strong>Min-Heap (Priority Queue)</strong>.</p><p>🔸 <strong>How it works:</strong></p><ol><li>Load the <strong>first element</strong> of each chunk into a <strong>Min-Heap</strong>.</li><li><strong>Extract the smallest element</strong> from the heap and <strong>write it to the final sorted output</strong>.</li><li><strong>Replace</strong> the extracted element with the <strong>next element</strong> from the same chunk.</li><li><strong>Repeat</strong> until all elements are merged!</li></ol><p>🔸 <strong>Example:</strong> If chunks look like this:</p><ul><li>chunk1: [2, 10, 23, 45]</li><li>chunk2: [1, 5, 30, 40]</li><li>chunk3: [7, 11, 25, 50]</li></ul><p>The heap starts as [2, 1, 7]. You pick 1 (the smallest), write it to the output, and <strong>replace it with the next element from chunk2 (</strong><strong>5)</strong>. Keep repeating until the heap is empty!</p><ul><li><strong>Time Complexity:</strong> O(N log K) (where N is the number of elements, K is the number of chunks).</li></ul><h3>Why This Approach Works</h3><ul><li><strong>Memory Efficiency:</strong> Only a small portion of data is loaded into RAM at a time.</li><li><strong>Scalability:</strong> Easily handles billions of elements with limited RAM.</li><li><strong>Practicality:</strong> Avoids expensive random disk access by reading and writing sequentially.</li></ul><p>This is the same technique that databases and large-scale systems use to sort massive datasets — it’s battle-tested and highly reliable.</p><h3>Optimizations for Better Performance</h3><ol><li><strong>Optimal Chunk Size:</strong> Experiment with chunk sizes to balance RAM usage and disk I/O.</li><li><strong>Parallel Sorting:</strong> Use multiple threads to sort chunks concurrently.</li><li><strong>Buffered I/O:</strong> Use buffered reads and writes to minimize disk access overhead.</li><li><strong>Compression:</strong> Compress chunks to save disk space, decompress during merging.</li></ol><p>With these optimizations, the process can become even faster and more efficient!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dae8df9bc444" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>