<?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 Franz Andel on Medium]]></title>
        <description><![CDATA[Stories by Franz Andel on Medium]]></description>
        <link>https://medium.com/@franzandel?source=rss-7d77f63d4db0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Ic95rrT9sr6XltO3nFesYg.jpeg</url>
            <title>Stories by Franz Andel on Medium</title>
            <link>https://medium.com/@franzandel?source=rss-7d77f63d4db0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 02:48:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@franzandel/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[You Know MCP Tools… But Do You Know the Other Two?]]></title>
            <link>https://medium.com/@franzandel/you-know-mcp-tools-but-do-you-know-the-other-two-f612160eccf3?source=rss-7d77f63d4db0------2</link>
            <guid isPermaLink="false">https://medium.com/p/f612160eccf3</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[genai]]></category>
            <category><![CDATA[mcp-server]]></category>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Franz Andel]]></dc:creator>
            <pubDate>Wed, 18 Feb 2026 14:01:02 GMT</pubDate>
            <atom:updated>2026-02-18T14:01:02.314Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*J9Akm45sDqH7_20Q" /><figcaption>Photo by <a href="https://unsplash.com/@alexazabache?utm_source=medium&amp;utm_medium=referral">Alex Azabache</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Most people who explore MCP stop at Tools and miss the bigger picture. But a complete MCP setup actually has three parts: <strong>Tools</strong>, <strong>Resources</strong>, and <strong>Prompts</strong>. Think of it like a smart home management system: if you only understand the remote control, you’ll never grasp how the sensors and automation rules make the whole house intelligent.</p><p>In this article, we’ll break down each component using real-world examples, show how they work together, and clarify when you should use each one.</p><p>If you want a quick foundation first, I’ve also written a beginner-friendly explainer on what MCP is <a href="https://medium.com/@franzandel/mcp-vs-api-why-theyre-not-competing-7c1544cd33d5">here</a>.</p><h3>MCP Lifecycle</h3><p>Let’s start by understanding the MCP Lifecycle :</p><figure><img alt="MCP Lifecycle Sequence Diagram" src="https://cdn-images-1.medium.com/max/1024/1*1uhYNvP_o8OAoI7bvTEFhw.png" /><figcaption>MCP Lifecycle Sequence Diagram</figcaption></figure><h3>Concrete Example</h3><p>Assume we have a <strong>Smart Home Management System :</strong></p><figure><img alt="MCP Concrete Example" src="https://cdn-images-1.medium.com/max/1024/1*3Je5x2HAWph0FZ_LWAhnvg.jpeg" /><figcaption>MCP Concrete Example</figcaption></figure><p>In this scenario, we have an MCP server that manages devices in a house. The <strong>Resources</strong> provide data (sensor readings), the <strong>Tool</strong>s allow action (turning devices on/off), and the <strong>Prompts</strong> give the LLM a template for a specific workflow (a daily status report).</p><h4>Setup</h4><pre>from fastmcp import FastMCP<br><br># Initialize the server<br>mcp = FastMCP(&quot;SmartHomeManager&quot;)<br><br># Mock database for our examples<br>sensor_data = {<br>    &quot;living_room&quot;: {&quot;temp&quot;: 22, &quot;humidity&quot;: 45, &quot;lights&quot;: False},<br>    &quot;kitchen&quot;:     {&quot;temp&quot;: 24, &quot;humidity&quot;: 50, &quot;lights&quot;: True}<br>}</pre><h4>Resources</h4><p>Resources provide context to the LLM. They are like “files” or “logs” that the model can read to understand the current state of the world.</p><pre>@mcp.resource(&quot;smarthome://sensors/{room}&quot;)<br>def get_sensor_data(room: str) -&gt; str:<br>    &quot;&quot;&quot;<br>    Reads the live temperature and status data for a specific room.<br>    &quot;&quot;&quot;<br>    if room not in sensor_data:<br>        return &quot;Error: Room not found.&quot;<br>    <br>    data = sensor_data[room]<br>    # Convert bool to string strictly for the display report<br>    light_status = &quot;ON&quot; if data[&#39;lights&#39;] else &quot;OFF&quot;<br><br>    return (f&quot;--- STATUS REPORT: {room.upper()} ---\n&quot;<br>            f&quot;Temperature: {data[&#39;temp&#39;]}°C\n&quot;<br>            f&quot;Humidity: {data[&#39;humidity&#39;]}%\n&quot;<br>            f&quot;Lights: {light_status}\n&quot;<br>            f&quot;--------------------------------&quot;)</pre><h4>Tools</h4><p>Tools are functions that the LLM can call to execute logic, interact with APIs, or change the state of the system.</p><pre>@mcp.tool()<br>def control_lights(room: str, status: bool) -&gt; str:<br>    &quot;&quot;&quot;<br>    Turns the lights on or off in a specific room.<br>    Args:<br>        room: The name of the room (e.g., &#39;living_room&#39;, &#39;kitchen&#39;)<br>        status: True for ON, False for OFF.<br>    &quot;&quot;&quot;<br>    if room not in sensor_data:<br>        return f&quot;Error: Room &#39;{room}&#39; does not exist.&quot;<br>    <br>    # Update the mock database<br>    sensor_data[room][&quot;lights&quot;] = status<br>    <br>    state_text = &quot;ON&quot; if status else &quot;OFF&quot;<br>    return f&quot;Success: Lights in {room} have been turned {state_text}.&quot;</pre><h4>Prompts</h4><p>Prompts are pre-built templates that help users get specific tasks done without typing a long explanation. They package up instructions and context.</p><pre>@mcp.prompt()<br>def morning_briefing() -&gt; list:<br>    &quot;&quot;&quot;<br>    Generates a prompt for a morning status check of the home.<br>    &quot;&quot;&quot;<br>    return [<br>        {<br>            &quot;role&quot;: &quot;user&quot;,<br>            &quot;content&quot;: (<br>                &quot;Please perform a morning check of the smart home system.&quot;<br>                &quot;1. Access the &#39;smarthome://sensors/living_room&#39; and &#39;smarthome://sensors/kitchen&#39; resources.&quot;<br>                &quot;2. Summarize the temperature and which lights were left on overnight.&quot;<br>                &quot;3. If any lights are on, ask me if I want to turn them off using the control_lights tool.&quot;<br>            )<br>        }<br>    ]</pre><h4>Flow</h4><ol><li><strong>User</strong> <strong>Selects Prompt:</strong> “Morning Briefing” → The LLM receives instructions to check the house.</li><li><strong>LLM</strong> <strong>Reads Resource:</strong> It reads smarthome://sensors/kitchen and sees the lights are &quot;on&quot;.</li><li><strong>LLM</strong> <strong>Suggests Action:</strong> “The kitchen lights were left on. Should I turn them off?”</li><li><strong>User</strong> <strong>Confirms:</strong> “Yes.”</li><li><strong>LLM</strong> <strong>Uses Tool:</strong> Calls control_lights(&quot;kitchen&quot;, False).</li></ol><p>Full Code can be found <a href="https://github.com/franzandel/MCPToolsResourcesPrompts">here</a>.</p><h3>Key Takeaways</h3><p>MCP isn’t just about Tools, it’s a three-part system: <strong>Tools, Resources, and Prompts</strong>. Miss one, and you’re not really using MCP… you’re only scratching its surface. Lock these components into your mental model if you want to understand how MCP actually delivers its power.</p><p>If this shifted how you see MCP, show it some love and follow for more sharp, no-fluff AI engineering insights.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f612160eccf3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RAG vs MCP: The Difference Most People Get Wrong]]></title>
            <link>https://medium.com/@franzandel/rag-vs-mcp-the-difference-most-people-get-wrong-7a2344573492?source=rss-7d77f63d4db0------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a2344573492</guid>
            <category><![CDATA[mcp-server]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[retrieval-augmented-gen]]></category>
            <category><![CDATA[genai]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Franz Andel]]></dc:creator>
            <pubDate>Tue, 03 Feb 2026 13:01:05 GMT</pubDate>
            <atom:updated>2026-02-03T13:01:05.208Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zDAHAOsvpEbnhXo9" /><figcaption>Photo by <a href="https://unsplash.com/@solomin?utm_source=medium&amp;utm_medium=referral">Dima Solomin</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>The Confusion</h3><p>Retrieval-Augmented Generation (RAG) and Model Context Protocol (MCP) are often lumped together as “ways to add context” to the LLM. That sounds reasonable, and it’s also the fastest way to misunderstand both.</p><p>If you’re still mixing up MCP with APIs, that misunderstanding starts even earlier. I broke that down in detail <a href="https://medium.com/@franzandel/mcp-vs-api-why-theyre-not-competing-7c1544cd33d5">here</a>.</p><h3>The Difference</h3><blockquote>RAG answers questions.<br>MCP performs actions.</blockquote><h4>Example</h4><blockquote>You want LLM to <strong>book a meeting</strong> for you.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vpD8twuOAE8UGwL2lHLGkA.png" /><figcaption>RAG vs MCP Example</figcaption></figure><h4>RAG</h4><p>You give the LLM:</p><ul><li>Your calendar documentation</li><li>Meeting rules</li><li>Company policy</li><li>Example schedules</li></ul><p>The LLM now knows:</p><ul><li>How meetings should be booked</li><li>What constraints exist</li><li>What a valid schedule looks like</li></ul><p>But here’s the catch:</p><p>RAG can only provide knowledge. It cannot:</p><ul><li>Check your real calendar</li><li>Create a meeting</li><li>Call any external system</li></ul><p>At best, it outputs:</p><blockquote>“Here’s how you should book the meeting.”</blockquote><h4>MCP</h4><p>With MCP, the LLM can:</p><ul><li>Call a calendar API</li><li>Check availability</li><li>Create the meeting</li><li>Return the result</li></ul><p>Not because it “knows more,” but because MCP lets the LLM execute tools, not just reason.</p><p>The LLM isn’t smarter. It’s <strong>connected</strong>.</p><h3>The Takeaway</h3><p>RAG and MCP don’t compete. They solve different layers of the problem.</p><p>RAG helps LLM <strong>know</strong> more.<br>MCP helps LLM <strong>do</strong> more.</p><p>If your system only needs better answers, RAG is enough.<br>If your system needs to take action, RAG alone will never be sufficient.</p><p>If this clarified RAG vs MCP faster than most explanations you’ve seen, follow for more straight-to-the-point breakdowns like this.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a2344573492" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MCP vs API: Why They’re Not Competing]]></title>
            <link>https://medium.com/@franzandel/mcp-vs-api-why-theyre-not-competing-7c1544cd33d5?source=rss-7d77f63d4db0------2</link>
            <guid isPermaLink="false">https://medium.com/p/7c1544cd33d5</guid>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[mcp-server]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Franz Andel]]></dc:creator>
            <pubDate>Thu, 22 Jan 2026 08:01:59 GMT</pubDate>
            <atom:updated>2026-01-22T08:01:59.969Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bLCxnk4zCpRdU8Bj" /><figcaption>Photo by <a href="https://unsplash.com/@siva_photography?utm_source=medium&amp;utm_medium=referral">Levart_Photographer</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Why MCP Exists</h3><p>You’ve probably heard of Model Context Protocol (MCP) being mentioned alongside modern AI systems.<br>But if you’re wondering <em>why it even exists</em> — or how it’s different from a regular API — you’re not alone.</p><p>MCP didn’t appear because APIs were broken.<br>It appeared because <strong>APIs don’t scale when multiple LLMs need to interact with multiple tools</strong>.</p><p>Before MCP, integrating LLMs with external systems created a <br><a href="https://huggingface.co/learn/mcp-course/unit1/key-concepts"><strong>M×N problem</strong></a>:</p><h4>Without MCP (MxN Problem)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*z48gNcGDvizzOUn5KoeyCA.png" /><figcaption><strong>MxN</strong> Problem</figcaption></figure><p>Every model needed custom logic for every tool it used. As the number of models and tools grew, integration complexity exploded.</p><p>MCP changes this by introducing an <strong>M+N structure</strong>, where models and tools no longer need to know about each other directly.</p><h4>With MCP (M+N Solution)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*asA_XAJrrCLvXbhtyKtWrg.png" /><figcaption><strong>M+N</strong> Solution</figcaption></figure><p>At first glance, this makes MCP look like “just another API layer.”<br>But that assumption misses the real difference.</p><h3>MCP vs API — The Real Difference</h3><ul><li>API is designed for <strong>software applications</strong> (mobile apps, web frontends)</li><li>MCP is designed for <strong>LLMs</strong> (OpenAI, Gemini, Claude, etc.)</li></ul><p>They both act as a bridge, but for different consumers.</p><h4>Example</h4><blockquote>Use Case: Find my last invoice, summarize it, and send it to my accountant.</blockquote><p><strong>API Approach</strong></p><ol><li>Manually decide which API to call</li><li>Handle auth per service</li><li>Hardcode sequencing logic</li><li>Maintain state between steps</li><li>Handle failures yourself</li></ol><p><strong>MCP Approach</strong></p><ol><li>MCP exposes tools (search, fetch, email)</li><li>Model decides: which tool to call, in what order &amp; with what parameters</li><li>Context is preserved automatically</li></ol><blockquote>API = your application control the flow<br>MCP = the LLM controls the flow</blockquote><p>MCP sits on top of APIs, acting as a structured bridge between LLMs and external systems. If your application doesn’t use LLMs or uses them only for text generation, MCP adds no value and can be safely ignored.</p><h3>When You Should Use Each</h3><p>✅ Use APIs when:</p><ul><li>Logic is fixed</li><li>Control matters</li></ul><p>✅ Use MCP when:</p><ul><li>Logic is dynamic</li><li>Tools must be orchestrated</li></ul><p>If this helped you understand MCP vs API in minutes instead of hours, follow for more concise tech breakdowns that actually make sense.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7c1544cd33d5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Target API Level 35 Migration Strategy]]></title>
            <link>https://medium.com/@franzandel/android-target-api-level-35-migration-strategy-fa32b879a2d6?source=rss-7d77f63d4db0------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa32b879a2d6</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[sdk]]></category>
            <category><![CDATA[material-design]]></category>
            <category><![CDATA[migration]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <dc:creator><![CDATA[Franz Andel]]></dc:creator>
            <pubDate>Thu, 31 Jul 2025 01:01:53 GMT</pubDate>
            <atom:updated>2025-07-31T15:50:19.176Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AuK1mOUxoAt1g1da" /><figcaption>Photo by <a href="https://unsplash.com/@ttrapani?utm_source=medium&amp;utm_medium=referral">Todd Trapani</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Prerequisites</h3><p><a href="https://proandroiddev.com/compilesdkversion-and-targetsdkversion-what-is-the-difference-b4227c663ba8">Target SDK definition</a></p><h3>Background</h3><blockquote>Starting August 31 2025:</blockquote><blockquote>New apps and app updates must target Android 15 (API level 35) or higher to be submitted to Google Play.</blockquote><p><strong>Notes: We can request a time extension to November 1, 2025, if the app update is not yet done.</strong></p><p>Details can be read <a href="https://developer.android.com/google/play/requirements/target-sdk">here</a>.</p><p>This time, API Level 35 introduces lots of changes, which can be read in these 2 links :</p><ul><li><a href="https://developer.android.com/about/versions/15/behavior-changes-all">https://developer.android.com/about/versions/15/behavior-changes-all</a></li><li><a href="https://developer.android.com/about/versions/15/behavior-changes-15">https://developer.android.com/about/versions/15/behavior-changes-15</a></li></ul><p>However, what I want to discuss is migration approaches specific to <a href="https://developer.android.com/about/versions/15/behavior-changes-15#window-insets">Window inset changes</a>.</p><h3>The Issue</h3><p>If we update targetSDK to 35, and try it out on Android API 35 devices, there will be an obscured and overlapping issue on our screen.</p><figure><img alt="Obscured and Overlapping issue Screen" src="https://cdn-images-1.medium.com/max/1024/1*9Hj-ydSXBTwVPqcgdfD6lg.png" /><figcaption><a href="https://developer.android.com/about/versions/15/behavior-changes-15#window-insets">Obscured and Overlapping issue Screen</a></figcaption></figure><p><strong>Notes: 3rd party SDK, which has Screen also impacted.</strong></p><p>This is because in Android 15 (API Level 35), <strong>edge-to-edge</strong> functionality is enforced, and our Screen is not properly handling padding insets yet, <strong>except</strong> if you already use <a href="https://developer.android.com/about/versions/15/behavior-changes-15#not-edge-to-edge"><strong>Material 3</strong> components</a>.</p><p>But since Material 3 was just released at the<strong> </strong><a href="https://developer.android.com/jetpack/androidx/releases/compose-material3#1.0.0"><strong>end of 2022</strong></a>. I assume that your legacy app will face this issue.</p><h3>Migration Approaches</h3><p>First, we need to understand Android’s UI term :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*WrIDElo-8T_Z1bDNoMAJ_Q.png" /></figure><p>Then, I will share our approach in doing the Migration. Our current codebase state is fully using Jetpack Compose Material 2, and the project scale is medium to large.</p><p>There are 2 Migration approaches we thought of :</p><h4>1. Big Bang approach</h4><p>Handle padding insets in the Material 2 Component level (we are already using centralized components), and directly update targetSDK to 35.</p><p>Pros :</p><ul><li>Single MR, easy to rollback</li><li>One-time development effort</li><li>One-time testing effort</li></ul><p>Cons :</p><ul><li>Hard to trace back if there is an issue in production</li><li>Possible back-and-forth development and testing effort</li><li>Can’t utilize feature flag capability</li></ul><h4>2. Partial approach</h4><p>Migrate Screen by Screen to support API 35, making sure it doesn’t break in <strong>both</strong> API 35 and &lt; API 35. Initially, targetSDK stays at 34, once fully migrated, then update targetSDK to 35.</p><p>Pros :</p><ul><li>Can be separated into several Sprints</li><li>Development workload can be separated into several engineers</li><li>Testing effort can be separated</li><li>Can utilize feature flag capability</li></ul><p>Cons :</p><ul><li>All changes must be done before <strong>August 31, 2025</strong></li><li>Engineers need to test in both API 35 and &lt; API 35</li><li>Handle padding insets at Screen level instead of Component level</li><li>Multiple MRs, which cause more effort if a rollback is needed</li></ul><p>For both of the above approaches, it is also possible to use Material 3, since <strong>some</strong> of the Material 3 components, by default, already <a href="https://developer.android.com/about/versions/15/behavior-changes-15#not-edge-to-edge">handle padding insets</a>. However, this will add additional effort for engineers.</p><p>In a glimpse, the 2nd approach is more ideal. However, concerning the <strong>timeline</strong>, we eventually chose a hybrid approach of those two :</p><ol><li>Sprint 1, handle the padding insets at the Component level; however targetSDK remains 34. We made sure this implementation works in both targetSDK 34 and 35.</li><li>Sprint 2, updating targetSDK to 35.</li></ol><p>Pros :</p><ul><li>If there is an issue in production, we can <strong>distinguish</strong> whether it comes from the wrong implementation or updating targetSDK to 35</li><li>Done within <strong>2 sprints</strong>, we can meet Google’s deadline, which is <strong>August 31, 2025</strong></li><li>A relatively small development effort is required, as we only apply it at the Component level</li><li>A relatively small testing effort is required, as engineer can use several random sampling screens, and QA can do Regression normally</li><li>Can utilize feature flag capability for 1st Sprint</li><li>Two MRs, easy to rollback if needed</li></ul><p>Cons :</p><ul><li>Engineer need to test in both API 35 and &lt; API 35</li></ul><p>Snippet of how we fix the issue using Material 2 :</p><pre>Scaffold(<br>    modifier = Modifier.fillMaxSize(),<br>    bottomBar = {<br>        Text(<br>            modifier = Modifier.navigationBarsPadding(),<br>            text = &quot;Bottom Bar&quot;<br>        )<br>    }<br>) { innerPadding -&gt;<br>    Text(<br>        modifier = Modifier<br>            .padding(innerPadding)<br>            .statusBarsPadding(),<br>        text = &quot;Status Bar&quot;<br>    )<br>}</pre><p>Full code can be checked below :</p><p><a href="https://github.com/franzandel/TargetSDK35WindowInsetsDemo">https://github.com/franzandel/TargetSDK35WindowInsetsDemo</a></p><h3>Conclusion</h3><p>Sometimes, the ideal solution is not always the path we should take; we should dynamically adapt to our current condition. The goal is to solve the problem with a calculated solution.</p><p>Let me know how your approach is in the comment section!</p><p>If you learn something new, do clap so I know if this article helps you! Follow me for more concise and insightful engineering content. Thank you for reading this far!</p><h3>References</h3><ul><li><a href="https://proandroiddev.com/compilesdkversion-and-targetsdkversion-what-is-the-difference-b4227c663ba8">https://proandroiddev.com/compilesdkversion-and-targetsdkversion-what-is-the-difference-b4227c663ba8</a></li><li><a href="https://developer.android.com/google/play/requirements/target-sdk">https://developer.android.com/google/play/requirements/target-sdk</a></li><li><a href="https://developer.android.com/about/versions/15/behavior-changes-all">https://developer.android.com/about/versions/15/behavior-changes-all</a></li><li><a href="https://developer.android.com/about/versions/15/behavior-changes-15">https://developer.android.com/about/versions/15/behavior-changes-15</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa32b879a2d6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dependency Locking Real World Use Case in Android]]></title>
            <link>https://medium.com/@franzandel/dependency-locking-real-world-use-case-in-android-3c9fe8b1b0cc?source=rss-7d77f63d4db0------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c9fe8b1b0cc</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[dependencies]]></category>
            <category><![CDATA[sdk]]></category>
            <category><![CDATA[gradle]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Franz Andel]]></dc:creator>
            <pubDate>Tue, 24 Jun 2025 02:01:28 GMT</pubDate>
            <atom:updated>2025-06-24T02:01:28.549Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nYM0s3T5H-tAgGaz" /><figcaption>Photo by <a href="https://unsplash.com/@clintadair?utm_source=medium&amp;utm_medium=referral">Clint Adair</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this article, I’m going to explain one of the real-world use cases that is <strong>not</strong> explicitly mentioned in <a href="https://docs.gradle.org/current/userguide/dependency_locking.html">Gradle’s official docs</a>.</p><h3>Prerequisite</h3><p><a href="https://docs.gradle.org/current/userguide/getting_started_dep_man.html">Basic understanding of Gradle’s dependency management.</a></p><h3>Background</h3><p>In a medium to large-scale project, we usually have lots of dependencies used to build our project. This includes official Android and third-party SDK dependencies.</p><p>When we either add or update <em>dependency X</em>, we are <strong>not</strong> aware of the transitive dependencies that may be <strong>bumped</strong> by it.</p><p>Example :</p><p><a href="https://github.com/franzandel/DependencyLockingSample">GitHub - franzandel/DependencyLockingSample: Android Dependency Locking sample implementation</a></p><p>In our project, we have these dependencies :</p><pre># libs.versions.toml<br><br>[versions]<br>...<br>okhttp = &quot;3.3.1&quot;<br>retrofit = &quot;2.8.1&quot; # internally uses okhttp 3.14.7<br><br>[libraries]<br>...<br>okhttp = { module = &quot;com.squareup.okhttp3:okhttp&quot;, version.ref = &quot;okhttp&quot; }<br>okhttp-logging = { module = &quot;com.squareup.okhttp3:logging-interceptor&quot;, version.ref = &quot;okhttp&quot; }<br>retrofit = { module = &quot;com.squareup.retrofit2:retrofit&quot;, version.ref = &quot;retrofit&quot; }</pre><p>When we build our app, it is <strong>automatically bumped</strong> to 3.14.7 <strong>without</strong> our awareness.</p><p>This may lead to 2 error possibilities :</p><ol><li><strong>Compiler error</strong>; this is still acceptable, as we can obtain the feedback directly.</li><li><strong>Runtime error</strong>; this is fatal, as we may miss it even after the Regression Test. <em>(This is what we are facing)</em></li></ol><p>This is where the <strong>Dependency Locking</strong> comes into play.</p><p>By the way, if you want to learn more about those 2 error possibilities. I explain more on those topics here :</p><p><a href="https://medium.com/@franzandel/simplified-way-of-maintaining-library-compatibilities-part-2-7a7e3c2b8fd2">Library Compatibilities: Simplified Explanation with Example [Part 2]</a></p><h3>Benefits</h3><ol><li>To be aware of all <strong>transitive dependencies&#39;</strong> version changes.</li><li>To be aware of the dependency version difference between <strong>Production</strong> and <strong>Lower Environments</strong>.</li><li>Ease of checking since the difference will be clearly conveyed in Git’s file changes feature.</li></ol><h3>How to Set Up</h3><p>By default, Dependency Locking is <strong>off</strong>, so we need to have some configurations to turn this on.</p><p>First, create dependency-locking.gradle.kts file :</p><pre>configurations {<br>    // Your configuration setup<br>    val envs = listOf(&quot;dev&quot;, &quot;prod&quot;) // adjust according to your environment<br>    val buildTypes = listOf(&quot;debug&quot;, &quot;release&quot;) // adjust according to your build type<br>    val targets = listOf(&quot;compile&quot;, &quot;runtime&quot;)<br><br>    envs.forEach { env -&gt;<br>        buildTypes.forEach { buildType -&gt;<br>            targets.forEach { target -&gt;<br>                val capitalizedBuildType = buildType.replaceFirstChar { it.uppercase() }<br>                val capitalizedTarget = target.replaceFirstChar { it.uppercase() }<br>                val configName = &quot;${env}${capitalizedBuildType}${capitalizedTarget}Classpath&quot;<br><br>                register(configName) {<br>                    resolutionStrategy.activateDependencyLocking()<br>                }<br><br>                // For some reason this needs to be added, otherwise will fail gradle sync<br>                val configNameCopy = &quot;${env}${capitalizedBuildType}${capitalizedTarget}ClasspathCopy&quot;<br>                register(configNameCopy) {<br>                    resolutionStrategy.activateDependencyLocking()<br>                }<br>            }<br>        }<br>    }<br>}<br><br>dependencyLocking {<br>    lockMode.set(LockMode.STRICT)<br>}</pre><p>The above script will activate Dependency Locking for all <strong>environments</strong> and <strong>build types</strong> that you have. Targets is set to compile and runtime since we will only lock the dependency for those two cases. LockMode is set to LockMode.STRICT since we want to fail the build if gradle.lockfile is missing or any dependency differences are found.</p><p>Then, connect build.gradle(app) to dependency-locking.gradle.kts file :</p><pre>plugins {<br>    ...<br>}<br>apply(from = &quot;../dependency-locking.gradle.kts&quot;)<br><br>android {<br>  ...<br>}<br><br>dependencies {<br>  ...<br>}</pre><p>I am connecting it to app module with the assumption that all dependencies are there. If you want to track dependencies per module, simply connect each module’s build.gradle to dependency-locking.gradle.kts .</p><p>Finally, run this script to generate gradle.lockfile file :</p><pre>./gradlew app:dependencies --write-locks</pre><p>gradle.lockfile file will be generated in {project_name}/app/gradle.lockfile :</p><pre># This is a Gradle generated file for dependency locking.<br># Manual edits can break the build and are not advised.<br># This file is expected to be part of source control.<br>androidx.activity:activity-compose:1.10.1=devDebugCompileClasspath,devDebugRuntimeClasspath,devReleaseCompileClasspath,devReleaseRuntimeClasspath,prodDebugCompileClasspath,prodDebugRuntimeClasspath,prodReleaseCompileClasspath,prodReleaseRuntimeClasspath<br>androidx.activity:activity-ktx:1.10.1=devDebugCompileClasspath,devDebugRuntimeClasspath,devReleaseCompileClasspath,devReleaseRuntimeClasspath,prodDebugCompileClasspath,prodDebugRuntimeClasspath,prodReleaseCompileClasspath,prodReleaseRuntimeClasspath<br>androidx.activity:activity:1.10.1=devDebugCompileClasspath,devDebugRuntimeClasspath,devReleaseCompileClasspath,devReleaseRuntimeClasspath,prodDebugCompileClasspath,prodDebugRuntimeClasspath,prodReleaseCompileClasspath,prodReleaseRuntimeClasspath<br>androidx.annotation:annotation-experimental:1.4.1=devDebugCompileClasspath,devDebugRuntimeClasspath,devReleaseCompileClasspath,devReleaseRuntimeClasspath,prodDebugCompileClasspath,prodDebugRuntimeClasspath,prodReleaseCompileClasspath,prodReleaseRuntimeClasspath<br>androidx.annotation:annotation-jvm:1.9.1=devDebugCompileClasspath,devDebugRuntimeClasspath,devReleaseCompileClasspath,devReleaseRuntimeClasspath,prodDebugCompileClasspath,prodDebugRuntimeClasspath,prodReleaseCompileClasspath,prodReleaseRuntimeClasspath<br>androidx.annotation:annotation:1.9.1=devDebugCompileClasspath,devDebugRuntimeClasspath,devReleaseCompileClasspath,devReleaseRuntimeClasspath,prodDebugCompileClasspath,prodDebugRuntimeClasspath,prodReleaseCompileClasspath,prodReleaseRuntimeClasspath<br>androidx.arch.core:core-common:2.2.0=devDebugCompileClasspath,devDebugRuntimeClasspath,devReleaseCompileClasspath,devReleaseRuntimeClasspath,prodDebugCompileClasspath,prodDebugRuntimeClasspath,prodReleaseCompileClasspath,prodReleaseRuntimeClasspath<br>androidx.arch.core:core-runtime:2.2.0=devDebugRuntimeClasspath,devReleaseRuntimeClasspath,prodDebugRuntimeClasspath,prodReleaseRuntimeClasspath<br>androidx.autofill:autofill:1.0.0=devDebugRuntimeClasspath,devReleaseRuntimeClasspath,prodDebugRuntimeClasspath,prodReleaseRuntimeClasspath<br>androidx.collection:collection-jvm:1.5.0=devDebugCompileClasspath,devDebugRuntimeClasspath,devReleaseCompileClasspath,devReleaseRuntimeClasspath,prodDebugCompileClasspath,prodDebugRuntimeClasspath,prodReleaseCompileClasspath,prodReleaseRuntimeClasspath<br>androidx.collection:collection-ktx:1.5.0=devDebugRuntimeClasspath,devReleaseRuntimeClasspath,prodDebugRuntimeClasspath,prodReleaseRuntimeClasspath<br>androidx.collection:collection:1.5.0=devDebugCompileClasspath,devDebugRuntimeClasspath,devReleaseCompileClasspath,devReleaseRuntimeClasspath,prodDebugCompileClasspath,prodDebugRuntimeClasspath,prodReleaseCompileClasspath,prodReleaseRuntimeClasspath<br>...<br>empty=devDebugCompileClasspathCopy,devDebugRuntimeClasspathCopy,devReleaseCompileClasspathCopy,devReleaseRuntimeClasspathCopy,prodDebugCompileClasspathCopy,prodDebugRuntimeClasspathCopy,prodReleaseCompileClasspathCopy,prodReleaseRuntimeClasspathCopy</pre><h3>How it works</h3><ol><li>gradle.lockfile file will be committed to the Repository and will act as the <strong>golden value</strong>.</li><li>If there are dependency changes, there will be a compiler error saying there is a mismatch between the current dependencies and the golden value.</li><li>Run ./gradlew app:dependencies --write-locks script in the terminal to generate or update gradle.lockfile file.</li><li>Once regenerated, utilize Git’s file changes feature to see what dependencies are affected (especially the <strong>transitive dependencies</strong>).</li></ol><h3>What’s next?</h3><p>If your project has CI Integration, you could add the dependency locking comparison logic to the pipeline :</p><ol><li>Get the file hash of the committed gradle.lockfile .</li><li>Run ./gradlew app:dependencies — write-locks to generate the current new gradle.lockfile and get the file hash of it.</li><li>Compare those 2 file hashes. If it matches, meaning the gradle.lockfile is updated; otherwise, it needs to be updated.</li></ol><p>If you learn something new, do clap so I know if this article helps you! Follow me for more concise and insightful engineering content. Thank you for reading this far!</p><h3>Reference</h3><ul><li><a href="https://docs.gradle.org/current/userguide/getting_started_dep_man.html">https://docs.gradle.org/current/userguide/getting_started_dep_man.html</a></li><li><a href="https://docs.gradle.org/current/userguide/dependency_locking.html">https://docs.gradle.org/current/userguide/dependency_locking.html</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c9fe8b1b0cc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[History of Big O notation]]></title>
            <link>https://medium.com/@franzandel/history-of-big-o-notation-e8b0cd4016a2?source=rss-7d77f63d4db0------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8b0cd4016a2</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[time-complexity]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[big-o-notation]]></category>
            <category><![CDATA[engineering]]></category>
            <dc:creator><![CDATA[Franz Andel]]></dc:creator>
            <pubDate>Tue, 27 May 2025 01:02:28 GMT</pubDate>
            <atom:updated>2025-05-27T01:02:28.031Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RMuNIen5iBaJAqMN" /><figcaption>Photo by <a href="https://unsplash.com/@didiofederico_photographer?utm_source=medium&amp;utm_medium=referral">Federico Di Dio photography</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Have you ever wondered how the Big O notation is formed? This article is meant to explain it.</p><h3>Prerequisites</h3><p><a href="https://en.wikipedia.org/wiki/Algorithm">Algorithm</a>.</p><p>In short, an Algorithm is a step-by-step process for solving a problem that consists of Input, Process, and Output.</p><p>What we want to focus on is the <strong>Process</strong> <strong>time</strong> of an Algorithm.</p><h3>History</h3><p>Let’s take the example of the <a href="https://en.wikipedia.org/wiki/Linear_search">Linear Search algorithm</a> :</p><pre>import time<br><br>def linear_search(arr, target):<br>    for i in range(len(arr)):<br>        if arr[i] == target:<br>            return i  # Return the index of the found element<br>    return -1  # Return -1 if not found<br><br># Example usage<br>arr = list(range(1, 1000000))  # Large input to show measurable time<br>target = 999999<br><br>start_time = time.time()  # Record start time<br>result = linear_search(arr, target)<br>end_time = time.time()  # Record end time<br><br># Output results<br>if result != -1:<br>    print(f&quot;Element found at index {result}&quot;)<br>else:<br>    print(&quot;Element not found&quot;)<br><br>print(f&quot;Execution time: {end_time - start_time:.6f} seconds&quot;)</pre><p>The Linear Search algorithm has a time complexity of<strong> Linear (O(n)), </strong>which is read as <strong>“Order of n”</strong>. But how can they come up with a time complexity of<strong> Linear (O(n))</strong>?</p><p>First, let’s try to execute the above code with 5 different cases in 2 different Online Compilers :</p><ol><li>Input Size = 1000, Target = 999</li><li>Input Size = 10000, Target = 9999</li><li>Input Size = 100000, Target = 99999</li><li>Input Size = 1000000, Target = 999999</li><li>Input Size = 10000000, Target = 9999999</li></ol><p>Online Compilers :</p><ol><li><a href="https://www.onlinegdb.com/online_python_compiler">https://www.onlinegdb.com/online_python_compiler</a></li><li><a href="https://www.boot.dev/playground/py">https://www.boot.dev/playground/py</a></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aEYq9zwth84uM8Fh9m41ww.png" /></figure><p>We can imagine Online Compiler as a Computer, so in the above case, we tested on 2 different Computers with <strong>different processing speeds</strong>. That is why the Execution Time is different.</p><p>From the graph above, we can conclude 2 things :</p><ol><li>Input Size grows = Execution Time grows.</li><li>Execution Time might be different between Online Compilers, however, the <strong>pattern</strong> remains the same, which is <strong>Linear (O(n))</strong>.</li></ol><p>That is also why Big O notation does <strong>not</strong> refer to Execution Time since Execution Time might be different between Computers. Instead, it refers to the <strong>pattern</strong>.</p><p>Big O breakdown :</p><p>Big = the most significant part of the algorithm.</p><p>O = Order of growth.</p><h3>Conclusion</h3><p>Big O notation doesn’t depend on a computer’s processing speed; instead, it shows the <strong>execution time pattern</strong> based on the algorithm’s input size.</p><p>Here are the references to the mostly used Big O Notation :</p><ol><li>Constant: O(1)</li><li>Logarithmic time: O(log n)</li><li>Linear time: O(n)</li><li>Linearithmic time: O(n log n)</li><li>Quadratic time: O(n²)</li><li>Exponential time: O(2^n)</li><li>Factorial time: O(n!)</li></ol><p>Also, Big O Notation is used for both Time Complexity and Space Complexity, which refers to the same notation as listed above.</p><p>If you learn something new, do clap so I know if this article helps you! Follow me for more concise and insightful engineering content. Thank you for reading this far!</p><h3>References</h3><ul><li><a href="https://youtu.be/fZc3ijGM0aM?list=PLMCXHnjXnTnszR6YSo1tQK2BMr15cC9Zh">https://youtu.be/fZc3ijGM0aM?list=PLMCXHnjXnTnszR6YSo1tQK2BMr15cC9Zh</a></li><li><a href="https://youtu.be/D6xkbGLQesk?list=PLBZBJbE_rGRV8D7XZ08LK6z-4zPoWzu5H">https://youtu.be/D6xkbGLQesk?list=PLBZBJbE_rGRV8D7XZ08LK6z-4zPoWzu5H</a></li><li><a href="https://www.bigocheatsheet.com/">https://www.bigocheatsheet.com/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8b0cd4016a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Short Polling vs Long Polling]]></title>
            <link>https://medium.com/@franzandel/short-polling-vs-long-polling-61ec22ae842c?source=rss-7d77f63d4db0------2</link>
            <guid isPermaLink="false">https://medium.com/p/61ec22ae842c</guid>
            <category><![CDATA[realtime]]></category>
            <category><![CDATA[polling]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[http-request]]></category>
            <category><![CDATA[websocket]]></category>
            <dc:creator><![CDATA[Franz Andel]]></dc:creator>
            <pubDate>Tue, 19 Nov 2024 02:01:56 GMT</pubDate>
            <atom:updated>2024-11-19T13:36:17.888Z</atom:updated>
            <content:encoded><![CDATA[<h3>Short Polling vs. Long Polling</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jvkJxH7ICUCyVKBm" /><figcaption>Photo by <a href="https://unsplash.com/@_staticvoid?utm_source=medium&amp;utm_medium=referral">Lucas Santos</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Have you ever heard of Short Polling and Long Polling in Software Development? If yes, are you able to differentiate those? Initially, you might think of the difference is at the duration of calling HTTP Request. However, this is not true. Let’s dive deep into the differences.</p><h3>Prerequisites</h3><p><a href="https://www.codecademy.com/article/http-requests">HTTP Request</a>.</p><h3>What is Polling?</h3><p>Polling is one of the techniques to get more Real-Time data by <strong>still</strong> using HTTP Request.</p><blockquote>Common use case is Get Payment Status.</blockquote><h3>Short Polling</h3><p>This one is simple, and I believe we have the same understanding here. Short Polling refers to doing HTTP Request in <em>X</em> time duration.</p><blockquote>For instance, hit GET /payment/status every 3 seconds.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B8jCA9XQIykWWWHjo_-QZQ.gif" /><figcaption>Short Polling illustration</figcaption></figure><h3>Long Polling</h3><p>This is where the misconception often happens. Developers often think of this as doing HTTP Request but with a longer time span. However, this is <strong>not</strong> correct.</p><p>Long Polling refers to doing HTTP Request <strong><em>once</em></strong> and Server is holding the Request open until new information is available. Purpose is, Client will be able to get more Real-Time data without making redundant HTTP Requests.</p><blockquote>For instance, hit GET /chat/message once and Response is returned after 3 seconds.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oa4DvUOqC5-PeBK7T5VltA.gif" /><figcaption>Long Polling illustration</figcaption></figure><p>However, please take note that there might be a chance for Timeout to happen. So both the Server and Client should handle this correctly.</p><h3>Conclusion</h3><p>Polling is used when the Server <strong>still</strong> wants to use HTTP Request without having to configure <strong>WebSockets</strong>.</p><p>Does that mean Long Polling is better than Short Polling? Not necessarily true, it will depend on your use cases. Here are some keys to consider :</p><p>Use Short Polling if :</p><ul><li>Doesn’t require immediate updates.</li><li>You need a quick and simple solution without requiring Server Configurations.</li></ul><p>Use Long Polling if :</p><ul><li>Need near Real-Time updates.</li><li>Need to preserve Server Loads.</li></ul><p>Here is the <a href="https://github.com/franzandel/ShortVsLongPolling">sample project</a> showcasing what I have explained above, just in case you need to check the code.</p><p>Hope you learn something new today or if you want me to discuss more about <strong>WebSockets</strong>, consider clapping or commenting below. Thank you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61ec22ae842c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Library Compatibilities: Simplified Explanation with Example [Part 2]]]></title>
            <link>https://medium.com/@franzandel/simplified-way-of-maintaining-library-compatibilities-part-2-7a7e3c2b8fd2?source=rss-7d77f63d4db0------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a7e3c2b8fd2</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[binary]]></category>
            <category><![CDATA[library-design]]></category>
            <dc:creator><![CDATA[Franz Andel]]></dc:creator>
            <pubDate>Wed, 30 Oct 2024 11:57:53 GMT</pubDate>
            <atom:updated>2025-06-19T13:27:19.952Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FjJglGDMSO55iar_" /><figcaption>Photo by <a href="https://unsplash.com/@wilking?utm_source=medium&amp;utm_medium=referral">Joshua Wilking</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In Part 2, or the last part, we will learn more about Binary Compatibility. If you haven’t checked the previous part, you can do so here :</p><p><a href="https://medium.com/@franzandel/simplified-way-of-maintaining-library-compatibilities-part-1-28430e76ce50">Library Compatibilities: Simplified Explanation with Example [Part 1]</a></p><h3>Binary Compatibility</h3><p>To understand better, I will explain the issue of Binary Compatibility which is called <strong>Binary Incompatibility. </strong>It refers to changes in an API or library that cause previously compiled binaries to fail at <strong>runtime</strong>.</p><p>Some common exceptions are : NoSuchMethodError, NoSuchFieldError, ClassNotFoundException, NoClassDefFoundError.</p><h4>What are those changes?</h4><p>Some of them are :</p><ul><li><strong>Removing or renaming <em>public</em> classes / methods</strong>: <br>Clients rely on these members. If they’re missing or renamed, the client can’t find them in the compiled binary.</li><li><strong>Changing method signatures</strong>: <br>Altering parameters or return types changes how methods are accessed, causing runtime failures.</li><li><strong>Reducing visibility:</strong> <br>Blocks client access, breaking their compiled code.<br>e.g. public to private modifier.</li><li><strong>Other Details can be found </strong><a href="https://github.com/Kotlin/binary-compatibility-validator?tab=readme-ov-file#what-makes-an-incompatible-change-to-the-public-binary-api"><strong>here</strong></a><strong>.</strong></li></ul><h4>Illustration</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2WJSstceDYXIG-xis_E1nQ.png" /><figcaption>Binary Incompatibility Illustration</figcaption></figure><p>Imagine we are building an App that has these dependencies :</p><ol><li>Common Features depends on Design Library v1.</li><li>App depends on Common Features and Design Library v2.</li></ol><blockquote><a href="https://docs.gradle.org/current/userguide/dependency_resolution.html#sub:resolution-strategy">Gradle will consider <em>all</em> requested versions, wherever they appear in the dependency graph. By default, it will select the <em>highest</em> version.</a></blockquote><p>When compiling App, Gradle <strong>by default</strong> resolves dependency to the highest version found, in this case, v2.</p><p>At a glance, it doesn’t seem to cause any issue from the client side, because in v2, they have provided a default value for the newly added parameter (usually called <strong>Source Compatible</strong>, refer to Part 1 for more details <a href="https://medium.com/@franzandel/simplified-way-of-maintaining-library-compatibilities-part-1-28430e76ce50">here</a>). However, let’s take a look deeper into the bytecode generated from both versions.</p><p>Design Library v1 bytecode :</p><pre>public static final fun send (Ljava/lang/String;)V</pre><p>Design Library v2 bytecode :</p><pre>public static final fun send (Ljava/lang/String;Ljava/lang/String;)V<br>public static synthetic fun send$default (Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)V</pre><p>Notice that the v1 bytecode is removed. When the user triggers an action that executes send function (from Common Features) will cause a<strong> Runtime Error </strong>(in this case NoSuchMethodError).</p><h4>How to resolve this?</h4><p>There are 3 options to solve this issue :</p><ol><li><strong>[Client Side]</strong> Downgrade Design Library to v1 and <strong>wait</strong> until Common Features update to v2. Then, upgrade the Design Library back to v2. This approach won’t work if App has hard requirements to use Design Library v2.</li><li><strong>[Client Side]</strong> Force gradle to use v1, however, this is not recommended since this might introduce a new issue, especially in a complex project.</li><li><strong>[SDK Side] [Recommended] </strong>Design Library engineers should handle this by providing the old implementation (usually with Deprecated Annotation to encourage client to migrate to a newer implementation). This <a href="https://github.com/Kotlin/binary-compatibility-validator">tool</a> can help in pointing out which implementation requires Binary Compatibility handling.</li></ol><pre>@Deprecated(<br>    message = &quot;Maintained for binary compatibility. Use send(name, address) instead&quot;,<br>    level = DeprecationLevel.HIDDEN<br>)<br>fun send(name: String) {<br>    ...<br>}<br>fun send(name: String, address: String = &quot;&quot;) {<br>    ...<br>}</pre><h4>What if the dependency version switched?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-QmSoGFdMPGFQ5LNYJ3btQ.png" /><figcaption>Binary Incompatibility version switched Illustration</figcaption></figure><p>Now, the dependency version is switched :</p><ol><li>Common Features depends on Design Library v2.</li><li>App depends on Common Features and Design Library v1.</li></ol><p>When compiling, Design Library in App will be bumped to v2 and successfully compiled since v2 signature provides a default value, otherwise will throw a Compiler Error. This refers to <a href="https://medium.com/@franzandel/simplified-way-of-maintaining-library-compatibilities-part-1-28430e76ce50"><strong>Source Compatibility</strong></a><strong>.</strong></p><p>The reason why this case is not throwing Runtime Error is that, bumped Design Library version in App is being compiled while Design Library in Common Features (SDK) <strong>is not</strong>.</p><p>I have created a sample project that reflects both diagrams above, just in case you want to try it out. Simply change the branch to test out the difference.</p><ol><li><a href="https://github.com/franzandel/DesignLibrary">Design Library</a></li><li><a href="https://github.com/franzandel/CommonFeatures">Common Features</a></li><li><a href="https://github.com/franzandel/BinaryCompatibility">Binary Compatibility (App)</a></li></ol><h3>Conclusion</h3><p>Pay attention to code that is precompiled and not. Precompiled code, has chances that lead to <strong>Runtime Error, </strong>while compiled code usually only leads to Compiler Error (safer).</p><p>These articles are simplified, as in real production, libraries might have more complex dependencies.</p><p>I hope this gives you a better clarity on how to handle compatibilities in Library. If yes, please do clap on these articles. Here is the full list of these articles series :</p><ol><li><a href="https://medium.com/@franzandel/simplified-way-of-maintaining-library-compatibilities-part-1-28430e76ce50">Library Compatibilities: Simplified Explanation with Example [Part 1]</a></li><li><a href="https://medium.com/@franzandel/simplified-way-of-maintaining-library-compatibilities-part-2-7a7e3c2b8fd2">Library Compatibilities: Simplified Explanation with Example [Part 2]</a></li></ol><p>If there are any doubts, please share them in the comment section.</p><p>Thank you and Happy learning!</p><h3>FAQs</h3><p>Q: If I only have 1 dependency on SDK, in the above case App depends on Design Library <strong>only</strong>, will this issue arise?<br>A: No, the issue will only arise if there is a version discrepancy with the above changes compiled into an Application.</p><p>Q: How long should SDK maintain the backward-compatible implementation?<br>A: Depends on your Compatibility Policy, in general, it is usually maintained for several releases before it is fully removed.</p><h3>References</h3><ul><li><a href="https://zsmb.co/maintaining-compatibility-in-kotlin-libraries/">Maintaining Compatibility in Kotlin Libraries</a></li><li><a href="https://www.youtube.com/watch?v=cCgXtpVPO-o">Evolving your Kotlin API painlessly for clients by Leonid Startsev</a></li><li><a href="https://kotlinlang.org/docs/api-guidelines-backward-compatibility.html">Backward compatibility guidelines for library authors</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a7e3c2b8fd2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Library Compatibilities: Simplified Explanation with Example [Part 1]]]></title>
            <link>https://medium.com/@franzandel/simplified-way-of-maintaining-library-compatibilities-part-1-28430e76ce50?source=rss-7d77f63d4db0------2</link>
            <guid isPermaLink="false">https://medium.com/p/28430e76ce50</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[sdk]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[library-design]]></category>
            <dc:creator><![CDATA[Franz Andel]]></dc:creator>
            <pubDate>Thu, 24 Oct 2024 00:57:38 GMT</pubDate>
            <atom:updated>2025-06-19T13:25:53.392Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ySlEdWZLOyT8jm2X" /><figcaption>Photo by <a href="https://unsplash.com/@thephotohiker?utm_source=medium&amp;utm_medium=referral">Michael Hoyt</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>There are gaps in understanding library compatibilities compared to client compatibilities in software engineering especially where binaries interact. Take the example of Java or Kotlin in Android Development, Objective-C or Swift in iOS Development, C++ or Rust or Java in Backend Development, etc. I will be using Kotlin in Android Development as an example.</p><h3>Prerequisite</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*di-CYxqwU-Oy1p_JwjPFKQ.png" /><figcaption>Dependency Diagram difference</figcaption></figure><p>There are differences in terms of compilation process when building APK for both diagrams above :</p><ol><li><strong>Design Library source resides in the same project as App</strong><br>When compiling, all sources in Design Library will be compiled together with App.</li><li><strong>Design Library as SDK</strong><br>When compiling, only App will be compiled, Design Library won’t be recompiled since it is already precompiled as aar.</li></ol><h3>Types of Compatibility</h3><p>In terms of Library Compatibilities, there are 2 types of it :</p><ol><li>Source Compatibility</li><li>Binary Compatibility</li></ol><h3>Source Compatibility</h3><p>Most developers already know that if we change a function signature, client usage should change as well.</p><p>Example :</p><p>Before</p><pre>fun send(name: String)</pre><p>After</p><pre>fun send(name: String, address: String)</pre><p>All send client usage should add address parameter, otherwise, there will be a Compiler Error. One way to avoid client changes is to provide a default value.</p><pre>fun send(name: String, address: String = &quot;&quot;)</pre><p>However, for Binary Compatibility, the case is different…</p><p><a href="https://medium.com/@franzandel/simplified-way-of-maintaining-library-compatibilities-part-2-7a7e3c2b8fd2">Library Compatibilities: Simplified Explanation with Example [Part 2]</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28430e76ce50" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[S.O.L.I.D. Principles: Simplified Explanation & Example]]></title>
            <link>https://medium.com/tunaiku-tech/s-o-l-i-d-principles-simplified-explanation-example-f7268ca75758?source=rss-7d77f63d4db0------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7268ca75758</guid>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[solid-principles]]></category>
            <category><![CDATA[solid]]></category>
            <dc:creator><![CDATA[Franz Andel]]></dc:creator>
            <pubDate>Wed, 03 Jun 2020 23:28:06 GMT</pubDate>
            <atom:updated>2020-06-03T23:28:06.357Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*itPTGwtalrvlA9dUhAtn_g.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@michelebit_">Michele Bitetto</a> on <a href="https://unsplash.com/s/photos/construct?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>You guys might have heard about S.O.L.I.D. before, for those of you who still have something missing about this concept maybe because the explanations aren’t telling the point or using a complicated wording. Or for those of you who are totally new and never heard of this before. Now you’re on the right page because I’m going to give you the Simplified Version of this concept. Of course with the violation &amp; correct example. Let’s Start!</p><p>First of all, before jumping into each Principle’s implementation, we need to understand what S.O.L.I.D. Principles is, why it is being used &amp; when you are going to implement this. Also, one thing to note is that I’ll consider you are familiar with <a href="https://en.wikipedia.org/wiki/Object-oriented_programming">OOP Concept</a> because S.O.L.I.D. Principles come after OOP. Otherwise, please visit this <a href="https://searchapparchitecture.techtarget.com/definition/object-oriented-programming-OOP">link</a> before going any further.</p><h3>Prerequisite</h3><p><a href="https://en.wikipedia.org/wiki/Object-oriented_programming">Object-Oriented Programming (OOP)</a></p><h3>What S.O.L.I.D. Principles is?</h3><p>S.O.L.I.D. Principles is a Software Development Principle for programming with OOP Paradigm. These Principles were introduced by Robert C. Martin (Uncle Bob) in his paper <a href="https://web.archive.org/web/20150906155800/http://www.objectmentor.com/resources/articles/Principles_and_Patterns.pdf"><em>Design Principles and Design Patterns (2000)</em></a><em>.</em></p><p>Yes, you’re not reading it wrongly nor I have a typo. It was written in 2000, 20 years ago since this article was published. But these Principles are still quite popular and are still being used widely in the world of OOP Paradigm.</p><h3>Why S.O.L.I.D. Principles?</h3><p>Because it makes your software :</p><ul><li>More Understandable<br>When you come back to your code six months later, you still understand what you wrote back then.</li><li>More Flexible<br>It’s quite easy when you need to add features in your code because all codes are loosely coupled.</li><li>More Maintainable<br>With the help of points 1 &amp; 2, you will be easier in maintaining your code.</li></ul><h3>When S.O.L.I.D. Principles are needed?</h3><blockquote>Everytime you code with OOP Paradigm</blockquote><p>Meaning, these Principles are not tied to specific Programming Languages like Kotlin, Swift, Golang, etc. This is a Principles that you’re going to have in your mind when you’re writing codes that support OOP Paradigm.</p><p>Up until here, you should have enough knowledge about the theory of using S.O.L.I.D. Principles. Now it’s about the time to dive into each Principle! Here I’ll provide you the Simplified Version of each Principle &amp; 2 Examples which consist of Violation and Correct Example.</p><p>The examples are in Kotlin. For those of you who have no experience in Kotlin, bear with me because I’m providing a general description &amp; the most simple code as I can. Also, this is not about the language, it’s more about the concept.</p><h3>S. in S.O.L.I.D. Principles</h3><p>First, let’s start with what does this S. stands for :</p><p><em>S. = Single Responsibility Principle</em></p><blockquote>From <a href="https://en.wikipedia.org/wiki/Single-responsibility_principle">Wikipedia</a> :<br>The <strong>single-responsibility principle</strong> (<strong>SRP</strong>) is a computer-programming principle that states that every <a href="https://en.wikipedia.org/wiki/Modular_programming">module</a> or <a href="https://en.wikipedia.org/wiki/Class_(computer_programming)">class</a> should have responsibility over a single part of the <a href="https://en.wikipedia.org/wiki/Software_feature">functionality</a> provided by the <a href="https://en.wikipedia.org/wiki/Software">software</a>, and that responsibility should be entirely <a href="https://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming)">encapsulated</a> by the class, module or function.</blockquote><p>Don’t worry I’ll give you the Simplified Version :</p><blockquote>Simplified Version :<br>A Class should only have 1 purpose.</blockquote><p>Yeah, that’s all the point of the Single Responsibility Principle. Now I’ll provide you the Example :</p><p><em>Violation Example :</em></p><pre><strong>class AgeCalculator</strong> {</pre><pre>    private val currentYear = Calendar.getInstance().get(Calendar.<em>YEAR</em>)<br><br>    fun calculate(birthYear: Int): String {<br>        return (currentYear - birthYear).toString()<br>    }<br><br> <strong>   fun isValid(birthYear: Int): Boolean {<br>        return currentYear &gt; birthYear<br>    }</strong><br>}</pre><p>From the highlighted code, we can see that in AgeCalculator class contains isValid() function which has different responsibility as what stated in the class name.</p><p>This is what violates the Single Responsibility Principle. Meaning, this class contains 2 functions with 2 responsibilities which are :</p><ol><li>calculate() for calculating age</li><li>isValid() for validating age</li></ol><p>So, what’s the impact if you leave this code as it is?</p><p>Imagine this class grows, and have 10 functions which have 10 responsibility each. When you have got something to modify, you would go to that class. First, you will face 10 functions with their own responsibility which going to make you spend more time understanding the code. Second, you will violate the next principle which is Open-Closed Principle because you’re modifying the existing class. Open-Closed Principle will be discussed after this principle.</p><p>So how do we refactor previous code to the correct one? Let’s see</p><p><em>Correct Example :</em></p><ul><li>First, we left calculate() function in AgeCalculator class.</li></ul><pre>class AgeCalculator {<br>    <strong>fun calculate(birthYear: Int): String {<br>        val currentYear = Calendar.getInstance().get(Calendar.<em>YEAR</em>)<br>        return (currentYear - birthYear).toString()<br>    }</strong><br>}</pre><ul><li>Then, we move isValid() function to separate AgeValidator class.</li></ul><pre>class AgeValidator {<br>    <strong>fun isValid(birthYear: Int): Boolean {<br>        val currentYear = Calendar.getInstance().get(Calendar.<em>YEAR</em>)<br>        return currentYear &gt; birthYear<br>    }</strong><br>}</pre><p>Here, we can see that each class has only 1 responsibility which would make us easier to understand the code and won’t violate the next Open-Closed Principle.</p><h3>O. in S.O.L.I.D. Principles</h3><p>Let’s start with what O. stands for :</p><p><em>O. = Open — Closed Principle</em></p><blockquote>From <a href="https://en.wikipedia.org/wiki/Open%E2%80%93closed_principle">Wikipedia</a> :<br>In <a href="https://en.wikipedia.org/wiki/Object-oriented_programming">object-oriented programming</a>, the <strong>open/closed principle</strong> states “<em>software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification</em>”; that is, such an entity can allow its behaviour to be extended without modifying its <a href="https://en.wikipedia.org/wiki/Source_code">source code</a>.</blockquote><p>Here’s the Simplified Version :</p><blockquote>Simplified Version :<br>A Class should be Open for Extension but Closed for Modification.</blockquote><p>Maybe some of you might be wondering why Extension is preferred rather than Modification. Actually, this Principle is trying to prevent us from seeing too much code in a class.</p><p>Imagine you have a class with 1000 lines of code, and you need to edit something from there. You might have felt overwhelmed the moment you think of it and haven’t even started editing the stuff that you’re going to edit.</p><p>Please note that Closed for Modification here doesn’t mean we totally may not edit stuff in classes, but the real meaning is, we can still edit stuff but with minimum changes. Here’s the example :</p><p><em>Violation Example :</em></p><ul><li>First, we have ShoesBrand enum class.</li></ul><pre>enum class ShoesBrand {<br>    NIKE, ADIDAS<br>}</pre><ul><li>Then, we have ShoesFactory class which have getShoesPrice function that accepts ShoesBrand as parameter.</li></ul><pre>class ShoesFactory {<br><br>    // How if there&#39;s a new brand of shoes?<br>    // If there are 10 ShoesBrand with Complex Calculation in it, this class will be very Complex</pre><pre>fun getShoesPrice(shoesBrand: ShoesBrand): Int {<br>        <strong>return when (shoesBrand) {<br>            ShoesBrand.NIKE -&gt; 2000<br>            ShoesBrand.ADIDAS -&gt; 1500<br>        }</strong><br>    }<br>}</pre><ul><li>At last, we have another class which uses ShoesFactory as an Object. Then call the getShoesPrice method with ShoesBrand.NIKE as argument.</li></ul><pre>val shoesFactory = ShoesFactory()<br>tvViolationShoesType.<em>text </em>= shoesFactory.getShoesPrice(ShoesBrand.NIKE).toString()</pre><p>The highlighted code is prone to be edited. Imagine if your Project Manager comes and says, please update Nike price to 2500 and add another Puma brand with a price of 3000.</p><p>With the above code, you will modify the highlighted code and that’s what violates this principle.</p><p>So how do we refactor previous code to the correct one? Let’s see</p><p><em>Correct Example :</em></p><ul><li>First, We have ShoesBrand abstract class with getShoesPrice abstract function.</li></ul><pre>abstract class ShoesBrand {<br>    abstract fun getShoesPrice(): Int<br>}</pre><ul><li>Then, we have NikeShoes class which extends from ShoesBrand.</li></ul><pre>class NikeShoes : ShoesBrand() {<br><strong>    override fun getShoesPrice() = 2500</strong><br>}</pre><ul><li>Then, we have AdidasShoes class which also extends from ShoesBrand.</li></ul><pre>class AdidasShoes : ShoesBrand() {<br>    override fun getShoesPrice() = 1500<br>}</pre><ul><li>Then, we have PumaShoes class which also extends from ShoesBrand.</li></ul><pre><strong>class PumaShoes : ShoesBrand() {<br>    override fun getShoesPrice() = 3000<br>}</strong></pre><ul><li>At last, we have another class which uses NikeShoes as an Object with the type of ShoesBrand. Then we call getShoesPrice method to show the shoes price into TextView.</li></ul><pre>val shoes: ShoesBrand = NikeShoes()<br>tvShoesType.<em>text </em>= shoes.getShoesPrice().toString()</pre><p>Now, with this code, we can easily update Nike Price without bothering to see other brands of Shoes, and here is what I mean we still need to edit the class but with minimum changes.</p><p>Lastly, we can easily extend from ShoesBrand if there’s a new Brand. Just like what we did in PumaShoes class.</p><h3>L. in S.O.L.I.D. Principles</h3><p>Here, we’ve arrived at Principle that causes brain explosion to most of us. But don’t worry I’ll give you the best-simplified version of this Principle. Let’s start with what L. stands for</p><p><em>L. = Liskov Substitution Principle</em></p><blockquote>From <a href="https://en.wikipedia.org/wiki/Behavioral_subtyping">Wikipedia</a> :<br>In <a href="https://en.wikipedia.org/wiki/Object-oriented_programming">object-oriented programming</a>, <strong>behavioral subtyping</strong> is the principle that subclasses should satisfy the expectations of clients accessing subclass objects through references of superclass type, not just as regards syntactic safety (absence of method-not-found errors and such) but also as regards behavioral correctness.</blockquote><p>I know a brain explosion there. Here’s the Simplified Version :</p><blockquote>Simplified Version :<br>Abstraction should be able to provide all Child Class needs.</blockquote><p>If you are still confused with my simplified version definition, try to look at the example below first, then come back to this definition and hopefully things will start making sense.</p><p><em>Violation Example :</em></p><ul><li>We have Jobs interface with doWork() function.</li></ul><pre>interface Jobs {<br>    fun doWork()<br>}</pre><ul><li>Then, we have Programmer class which implements Jobs interface.</li></ul><pre>class Programmer : Jobs {<br><br>    override fun doWork() {<br>        <em>println</em>(&quot;Working on Software Development Project&quot;)<br>    }<br>}</pre><ul><li>Then, we have Salesman class which also implements Jobs interface.</li></ul><pre>class Salesman : Jobs {<br><br>    override fun doWork() {<br>        <em>println</em>(&quot;Working on Selling Goods&quot;)<br>    }<br><br><strong>    fun talkToCustomer() {<br>        <em>println</em>(&quot;I talk to Customer Everyday&quot;)<br>    }</strong><br>}</pre><ul><li>Lastly, we have another class which uses Programmer as an Object with the type of Jobs. Then call the doWork() method.</li></ul><pre>val jobs: Jobs = Programmer()<br>jobs.doWork()</pre><p>This is okay because doWork() method is supported by Jobs interface. So this does not violate the Principle yet.</p><p>So where’s the Violating one? Please be patient, the violating part is about to come :</p><ul><li>Lastly, really the last one, the code is pretty much the same as before. We just replace Salesman class into Programmer class.</li></ul><pre>val jobs: Jobs = Salesman()<br>jobs.doWork()<br><strong>if (jobs is Salesman) {<br>    jobs.talkToCustomer()<br>}</strong></pre><p>Here comes the violation part, pay attention to the highlighted code we check if jobs is Salesman then we cast it to Salesman and then call the talkToCustomer() method.</p><p>This is what Liskov Substitution Principle told us not to do. Jobs interface should be able to provide what is needed by the child class.</p><p>But there is something to note here, all things that are defined in an interface should be implemented correctly by the child class otherwise we’ll violate the next principle which is Interface Segregation Principle. Interface Segregation Principle will be discussed after this principle.</p><p>Let’s see how we refactor previous code into the correct one :</p><p><em>Correct Example :</em></p><ul><li>First, we have Jobs interface with doWork() and talkToCustomer() functions.</li></ul><pre>interface Jobs {<br>    fun doWork()<br><strong>    fun talkToCustomer()</strong><br>}</pre><ul><li>Then, we have Programmer class which implements Jobs interface.</li></ul><pre>class Programmer : Jobs {<br><br>    override fun doWork() {<br>        <em>println</em>(&quot;Working on Software Development Project&quot;)<br>    }<br><br>    override fun talkToCustomer() {<br>        <em>println</em>(&quot;I seldom talk to Customer&quot;)<br>    }<br>}</pre><ul><li>Then, we have Salesman class which also implements Jobs interface.</li></ul><pre>class Salesman : Jobs {<br><br>    override fun doWork() {<br>        <em>println</em>(&quot;Working on Selling Goods&quot;)<br>    }<br><br>    override fun talkToCustomer() {<br>        <em>println</em>(&quot;I talk to Customer Everyday&quot;)<br>    }<br>}</pre><ul><li>Lastly, we have another class which uses Salesman as an Object with the type of Jobs. Then call the doWork() and talkToCustomer() methods.</li></ul><pre>val jobs: Jobs = Salesman()<br>jobs.doWork()<br><strong>jobs.talkToCustomer()</strong></pre><p>Here you can see that Jobs interface has got talkToCustomer() function. So, in order to use talkToCustomer() method, there is no need for us to check if jobs is Salesman or not anymore.</p><p>Hopefully reaching this part, your brain is not exploding anymore.</p><h3>I. in S.O.L.I.D. Principles</h3><p>We’ve reached the fourth Principle, the second last one. Let’s start with what I. stands for</p><p><em>I. = Interface Segregation Principle</em></p><blockquote>From <a href="https://en.wikipedia.org/wiki/Interface_segregation_principle">Wikipedia</a> :<br>In the field of <a href="https://en.wikipedia.org/wiki/Software_engineering">software engineering</a>, the <strong>interface-segregation principle</strong> (<strong>ISP</strong>) states that no client should be forced to depend on methods it does not use.</blockquote><p>The most simple Definition of Wikipedia so far. But here’s the Simplified Version :</p><blockquote>Simplified Version :<br>Small Interface is better than Big Interface.</blockquote><p>This principle is the next stage after the Liskov Substitution Principle where functions that we define in abstraction should be implemented correctly. Meaning, we should not force child class to implement things that they can’t do.</p><p>As we know, everything that is defined in Interface or abstract function should be implemented by the child class, otherwise, it would output a compiler error. So, we’re encouraged to separate interface into a smaller one. Here’s the example :</p><p><em>Violation Example :</em></p><ul><li>First, we have OnClickListener interface with onClick() and onLongClick() functions.</li></ul><pre>interface OnClickListener {<br>    fun onClick()<br><strong>    fun onLongClick()</strong><br>}</pre><ul><li>Then, we have ISViolationActivity class which implements OnClickListener interface.</li></ul><pre>class ISViolationActivity : AppCompatActivity(), OnClickListener {<br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.<em>activity_interface_segregation</em>)<br><br>        btnChangeName.setOnClickListener <strong>{<br>            </strong>onClick()<br>        <strong>}<br>    </strong>}<br><br>    @SuppressLint(&quot;SetTextI18n&quot;)<br>    override fun onClick() {<br>        tvName.<em>text </em>= &quot;Franz Andel&quot;<br>    }<br><br>    <strong>override fun onLongClick() {<br>        // This function is not used, but is forced to be implemented<br>    }</strong><br>}</pre><p>The interface consists of 2 functions in which if we only need one of the function inside that interface which is onClick() function, but we are forced to implement both of the functions. And this is what violates the principle. We should separate Interface into a smaller one so we can choose which to be used based on what we need.</p><p>Here’s how we refactor previous code into the correct one :</p><p><em>Correct Example :</em></p><ul><li>First, we have OnClickListener interface with onClick() function.</li></ul><pre>interface OnClickListener {<br><strong>    fun onClick()</strong><br>}</pre><ul><li>Then, we have OnLongClickListener interface with onLongClick() function.</li></ul><pre>interface OnLongClickListener {<br>    fun onLongClick()<br>}</pre><ul><li>Lastly, we have ISBestPracticeActivity class which implements OnClickListener interface.</li></ul><pre>// Make a Smaller Interface, so Child Class can choose which Interface to be Implemented</pre><pre>class ISBestPracticeActivity : AppCompatActivity(), <strong>OnClickListener</strong> {<br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.<em>activity_interface_segregation</em>)<br><br>        btnChangeName.setOnClickListener <strong>{<br>            </strong>onClick()<br>        <strong>}<br>    </strong>}<br><br>    @SuppressLint(&quot;SetTextI18n&quot;)<br><strong>    override fun onClick() {<br>        tvName.<em>text </em>= &quot;Franz Andel&quot;<br>    }</strong><br>}</pre><p>Now with this code, we can easily choose which interface that we need and then implement it.</p><p>In the example, we only need onClick() function so we only implement OnClickListener interface, but in the future, there might be a chance for you to need onLongClick() function too. This is simply solved by implementing both OnClickListener &amp; OnLongClickListener interface. As you may know, in Java or Kotlin we can implement more than 1 interface.</p><h3>D. in S.O.L.I.D. Principles</h3><p>Finally, we’ve reached the last Principle. Let’s start with what D. stands for</p><p><em>D. = Dependency Inversion Principle</em></p><blockquote>From <a href="https://en.wikipedia.org/wiki/Dependency_inversion_principle">Wikipedia</a> :<br>In <a href="https://en.wikipedia.org/wiki/Object-oriented_design">object-oriented design</a>, the <strong>dependency inversion principle</strong> is a specific form of <a href="https://en.wikipedia.org/wiki/Coupling_(computer_programming)">decoupling</a> software <a href="https://en.wikipedia.org/wiki/Modular_programming">modules</a>.</blockquote><p>The shortest definition of Wikipedia at last. Here’s the Simplified Version :</p><blockquote>Simplified Version :<br>A Class should depend on Abstraction, not Implementation.</blockquote><p>Let’s get into the example to make things clearer :</p><p><em>Violation Example :</em></p><ul><li>First, we have Dollar class with currency() function.</li></ul><pre>class Dollar {<br><strong>    fun currency() = &quot;$&quot;</strong><br>}</pre><ul><li>Then, we have Rupiah class with moneyCurrency() function.</li></ul><pre>class Rupiah {<br><strong>    fun moneyCurrency() = &quot;Rp.&quot;</strong><br>}</pre><ul><li>Lastly, we have DIViolationActivity class with a setter function setConversion that accepts Dollar class as parameter and to show currency to the TextView, we call dollar.currency() method.</li></ul><pre>class DIViolationActivity : AppCompatActivity() {<br><br>    // How if you want to change dollarViolation to RupiahViolation<br>    // while dollarViolation is used in many places?</pre><pre><strong>    private lateinit var dollar: Dollar</strong><br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.<em>activity_dependency_inversion</em>)<br><br><strong>        setConversion(Dollar())</strong><br>        setUI()<br>    }<br><br><strong>    private fun setConversion(dollar: Dollar) {<br>        this.dollar = dollar<br>    }</strong><br><br>    @SuppressLint(&quot;SetTextI18n&quot;)<br>    private fun setUI() {<br>        tvMyMoney.<em>text </em>= <strong>&quot;${dollar.currency()}5.000&quot;</strong><br>    }<br>}</pre><p>Here we have 2 implementation classes with their own currency. In order to call currency() method in Dollar, we make an object of it.</p><p>Now, imagine how if your Project Manager comes and says, please change the currency of our money into Rupiah.</p><p>With this code, you definitely need to change :</p><ul><li>the variable of dollar into Rupiah,</li><li>setConversion argument into Rupiah(),</li><li>setConversion function’s parameter into Rupiah</li><li>dollar.currency() into rupiah.moneyCurrency().</li></ul><p>We can conclude that there are 4 efforts there. And this is what violates the Principle.</p><p>Here’s how we refactor the previous 4 efforts code into 1 effort code :</p><p><em>Correct Example :</em></p><ul><li>First, we have MoneyConversion interface with currency() function.</li></ul><pre>interface MoneyConversion {<br>    fun currency(): String<br>}</pre><ul><li>Then, we have Dollar class which implements MoneyConversion interface.</li></ul><pre><strong>class Dollar: MoneyConversion</strong> {<br>    override fun currency() = &quot;$&quot;<br>}</pre><ul><li>Then, we have Rupiah class which also implements MoneyConversion interface.</li></ul><pre><strong>class Rupiah: MoneyConversion</strong> {<br>    override fun currency() = &quot;Rp.&quot;<br>}</pre><ul><li>Lastly, we have DIBestPracticeActivity class with a setter function setConversion that accepts MoneyConversion interface as parameter and to show currency to the TextView, we call moneyConversion.currency() method.</li></ul><pre>class DIBestPracticeActivity : AppCompatActivity() {<br><br><strong>    private lateinit var moneyConversion: MoneyConversion</strong><br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.<em>activity_dependency_inversion</em>)<br><br>        // It can be easily changed to Rupiah<br><strong>        setConversion(Dollar())</strong><br>        setUI()<br>    }<br><br><strong>    private fun setConversion(moneyConversion: MoneyConversion) {<br>        this.moneyConversion = moneyConversion<br>    }</strong><br><br>    @SuppressLint(&quot;SetTextI18n&quot;)<br>    private fun setUI() {<br>        tvMyMoney.<em>text </em>= &quot;${moneyConversion.currency()}5.000&quot;<br>    }<br>}</pre><p>Now, we’ve made DIBestPracticeActivity class depends on its Abstraction which is MoneyConversion interface.</p><p>With this code, we can easily change setConversion() argument to Rupiah(). And this is only 1 effort.</p><h3>Conclusion</h3><p>This concept will boost your productivity if implemented correctly because your code will be loosely coupled &amp; easier to read.</p><p>If you need to look directly into the full source code. You can clone it from here :</p><p><a href="https://github.com/franzandel/SOLID_Tutorial">franzandel/SOLID_Tutorial</a></p><p>I hope you get a better understanding of this concept after reading this. If you do have any suggestion please leave it in the comment section.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7268ca75758" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tunaiku-tech/s-o-l-i-d-principles-simplified-explanation-example-f7268ca75758">S.O.L.I.D. Principles: Simplified Explanation &amp; Example</a> was originally published in <a href="https://medium.com/tunaiku-tech">Tunaiku Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>