<?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 Deekshasinghal on Medium]]></title>
        <description><![CDATA[Stories by Deekshasinghal on Medium]]></description>
        <link>https://medium.com/@deekshasinghal3?source=rss-b152a198a3f4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*bfTAuI26iaNrTlmqbnS6eQ.jpeg</url>
            <title>Stories by Deekshasinghal on Medium</title>
            <link>https://medium.com/@deekshasinghal3?source=rss-b152a198a3f4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 02:29:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@deekshasinghal3/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[Why We Are More Loving Kotlin Collections ❤️]]></title>
            <link>https://medium.com/@deekshasinghal3/why-we-are-more-loving-kotlin-collections-%EF%B8%8F-689b1156feaf?source=rss-b152a198a3f4------2</link>
            <guid isPermaLink="false">https://medium.com/p/689b1156feaf</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[kotlin-vs-java]]></category>
            <category><![CDATA[collections-framework]]></category>
            <dc:creator><![CDATA[Deekshasinghal]]></dc:creator>
            <pubDate>Tue, 09 Sep 2025 03:18:21 GMT</pubDate>
            <atom:updated>2025-09-09T08:15:04.400Z</atom:updated>
            <content:encoded><![CDATA[<p>Java collections have been our reliable old friends, but Kotlin collections… oh boy, they feel like the cool, stylish upgrade we didn’t know we needed. Think of it as upgrading from a brick phone 📟 to a smartphone 📱. Both work, but one just feels right.</p><p>Let’s dive into why Kotlin collections make us fall in love with coding all over again.</p><h3>1. Null Safety: The Warm Blanket</h3><p>In Java, NullPointerException is like that uninvited guest who ruins the party. Kotlin, on the other hand, wraps us in a warm blanket of null safety.</p><pre>val list = listOf(&quot;A&quot;, &quot;B&quot;)<br>println(list.getOrNull(5)) // null, no crash</pre><p>No more ugly if (list != null) checks everywhere. Collections play nicely with nullability.</p><h3>2. Read-Only vs Mutable: Brick Phone vs Smartphone</h3><p>In Java, mutability sometimes sneaks in without warning. Kotlin makes it super clear:</p><pre>val readOnly = listOf(&quot;Apple&quot;, &quot;Banana&quot;)  // Read-only<br>val mutable = mutableListOf(&quot;Orange&quot;)     // Mutable<br>mutable.add(&quot;Mango&quot;)<br>// readOnly.add(&quot;Kiwi&quot;) ❌ Compile-time error</pre><p>You immediately know what you can and can’t change. It’s like moving from a locked-down brick phone to a smartphone — you know exactly what apps you can install.</p><h3>⚡ A Quick Clarification: List vs listOf</h3><p>This confuses a lot of people at first:</p><ul><li><strong>List&lt;T&gt;</strong> → the <strong>type</strong> (blueprint). It says: “I’m a read-only list.”</li><li><strong>listOf()</strong> → the <strong>function</strong> that actually creates an instance of that list.</li></ul><pre>fun printNames(names: List&lt;String&gt;) {<br>    println(names.joinToString())<br>}<br>val fruits = listOf(&quot;Apple&quot;, &quot;Banana&quot;) // returns List&lt;String&gt;<br>printNames(fruits)</pre><p>👉 Same goes for MutableList (type) vs mutableListOf() (function).</p><p>Think of it like this:</p><ul><li>List = the idea of a smartphone.</li><li>listOf() = going to the store and actually buying one.</li></ul><h3>3. Clean &amp; Short Syntax</h3><p>Kotlin’s collection functions feel like poetry compared to Java’s boilerplate.</p><pre>listOf(1, 2, 3, 4, 5)<br>    .filter { it % 2 == 0 }<br>    .map { it * it }<br>    .forEach { println(it) }<br>// Output: 4, 16</pre><p>Readable, concise, and elegant.</p><h3>4. Sequences: Lazy Magic</h3><p>Collections process eagerly, but <strong>sequences</strong> are lazy — they only compute what you really need.</p><pre>val result = generateSequence(1) { it + 1 }<br>    .take(10)<br>    .map { it * it }<br>    .filter { it % 2 == 0 }<br>    .toList()<br>println(result) // [4, 16, 36, 64, 100]</pre><p>Perfect when working with large datasets. Efficiency served fresh.</p><h3>5. Custom Extension Functions</h3><p>Sometimes the standard library doesn’t cover <em>your</em> use case. No problem — Kotlin lets you extend collections with your own helpers.</p><pre>fun &lt;T&gt; List&lt;T&gt;.secondOrNull() = if (size &gt;= 2) this[1] else null<br>println(listOf(&quot;A&quot;, &quot;B&quot;, &quot;C&quot;).secondOrNull()) // B</pre><p>Feels like superpowers for your collections.</p><h3>6. Advanced APIs to Fall in Love With</h3><p>Kotlin ships with gems like:</p><pre>val numbers = listOf(1, 2, 3, 4, 5, 6)<br>println(numbers.groupBy { it % 2 == 0 }) <br>// {false=[1, 3, 5], true=[2, 4, 6]}<br>val (even, odd) = numbers.partition { it % 2 == 0 }<br>// even=[2, 4, 6], odd=[1, 3, 5]</pre><p>You’ll find groupBy, partition, zip, windowed, and more—tools that feel like they were built just for developers’ happiness.</p><h3>7. A Balanced Take</h3><p>Before we get carried away, let’s be real:</p><ul><li>Read-only lists in Kotlin aren’t <em>truly immutable</em> (you can still cast and modify).</li><li>Overusing asSequence() on small lists might hurt performance.</li><li>Java interop sometimes allows modifications under the hood.</li></ul><p>But knowing these quirks keeps us safe.</p><h3>8. Wrap-Up &amp; Resources</h3><p>Kotlin collections take something we already knew (Java collections) and make them clearer, safer, and <em>so much more fun</em>. They’re the reason we sometimes smile while coding.</p><p>👉 Further Reading:</p><ul><li><a href="https://kotlinlang.org/docs/java-to-kotlin-collections-guide.html">Kotlin Official Docs: Collections</a></li></ul><p>That’s it — you’ve got the warmth of null safety, the clarity of read-only vs mutable, the magic of sequences, and the power of advanced APIs.</p><p>Happy coding, Kotlin lovers! 💛</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=689b1156feaf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Visitor Pattern in Android: What, Why & Kotlin-Friendly Alternatives]]></title>
            <link>https://medium.com/@deekshasinghal3/visitor-pattern-in-android-what-why-kotlin-friendly-alternatives-518c44dcc3d1?source=rss-b152a198a3f4------2</link>
            <guid isPermaLink="false">https://medium.com/p/518c44dcc3d1</guid>
            <category><![CDATA[visitor-pattern]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Deekshasinghal]]></dc:creator>
            <pubDate>Mon, 28 Jul 2025 10:03:44 GMT</pubDate>
            <atom:updated>2025-07-28T10:13:30.190Z</atom:updated>
            <content:encoded><![CDATA[<h3>1. What Is the Visitor Pattern?</h3><p>The <strong>Visitor Pattern</strong> is a classic behavioral design pattern used to <strong>separate an algorithm from the objects it operates on</strong>.</p><p>Instead of adding logic inside your objects, the logic is encapsulated in a “visitor” that <strong>visits</strong> each object and performs operations based on its type.</p><blockquote><em>✅ Keep your objects clean<br>✅ Move unrelated operations (like logging, exporting, analytics) to visitors</em></blockquote><h4>Classic structure:</h4><ul><li><strong>Element interface</strong> — exposes accept(visitor)</li><li><strong>Concrete elements</strong> — implement accept, and delegate to visitor.visit(this)</li><li><strong>Visitor interface</strong> — defines visit() for each element type</li><li><strong>Concrete visitor</strong> — performs specific behavior (logging, styling, exporting, etc.)</li></ul><h3>2. Kotlin Alternative: Sealed Classes + when</h3><p>In idiomatic Kotlin, many developers use <strong>sealed classes</strong> and smart casting to achieve similar outcomes in simpler scenarios.</p><pre>sealed class ViewType<br>data class Button(val label: String): ViewType()<br>data class TextView(val text: String): ViewType()<br><br>fun log(view: ViewType) {<br>    when(view) {<br>        is Button -&gt; println(&quot;Button: ${view.label}&quot;)<br>        is TextView -&gt; println(&quot;Text: ${view.text}&quot;)<br>    }<br>}</pre><h4>Pros:</h4><ul><li>Concise</li><li>Native Kotlin syntax</li><li>Great for closed type hierarchies</li></ul><h4>But…</h4><p>Sealed classes only work <strong>when you own all the types</strong> and don’t expect frequent new operations.</p><h3>3. Why Use Visitor Pattern in Android?</h3><p>Let’s say you’re building a large-scale <strong>shopping app</strong>, and you have reusable UI views like:</p><ul><li>ProductCard</li><li>DiscountBanner</li><li>ReviewView</li></ul><p>Now your team wants to:</p><ul><li>Track analytics on all UI elements</li><li>Export their data to JSON</li><li>Log debug properties</li></ul><p>If you use if or when everywhere, your logic becomes hard to manage.<br> Worse: You pollute your UI components with responsibilities they shouldn’t have.</p><h3>That’s where the Visitor Pattern shines:</h3><ul><li>✅ Add new operations (e.g. analytics, exporting) without modifying existing classes</li><li>✅ Avoid long when/if chains</li><li>✅ Clean separation of concerns</li></ul><h3>4. Implementing the Visitor Pattern in Kotlin (Shopping App Example)</h3><p>Let’s implement the visitor pattern for a shopping app.</p><h4>Visitor Interface:</h4><pre>interface ShoppingViewVisitor {<br>    fun visit(card: ProductCard)<br>    fun visit(banner: DiscountBanner)<br>    fun visit(review: ReviewView)<br>}</pre><h4>Visitable Interface:</h4><pre>interface VisitableView {<br>    fun accept(visitor: ShoppingViewVisitor)<br>}</pre><h4>UI Views (Elements):</h4><pre>class ProductCard(val name: String, val price: Double): VisitableView {<br>    override fun accept(visitor: ShoppingViewVisitor) = visitor.visit(this)<br>}<br>class DiscountBanner(val discountText: String): VisitableView {<br>    override fun accept(visitor: ShoppingViewVisitor) = visitor.visit(this)<br>}<br>class ReviewView(val user: String, val rating: Int): VisitableView {<br>    override fun accept(visitor: ShoppingViewVisitor) = visitor.visit(this)<br>}</pre><h4>Visitor Implementation:</h4><pre>class AnalyticsVisitor: ShoppingViewVisitor {<br>    override fun visit(card: ProductCard) {<br>        println(&quot;ProductCard: ${card.name}, ₹${card.price}&quot;)<br>    }<br><br>    override fun visit(banner: DiscountBanner) {<br>        println(&quot;Banner: ${banner.discountText}&quot;)<br>    }<br><br>    override fun visit(review: ReviewView) {<br>        println(&quot;Review by ${review.user}: ${review.rating}★&quot;)<br>    }<br>}</pre><h3>Using It in Code</h3><pre>val views: List&lt;VisitableView&gt; = listOf(<br>    ProductCard(&quot;Mouse&quot;, 799.0),<br>    DiscountBanner(&quot;20% OFF&quot;),<br>    ReviewView(&quot;Alice&quot;, 5)<br>)<br>val analytics = AnalyticsVisitor()<br>views.forEach { it.accept(analytics) }</pre><blockquote>No if/when.<br>Clean separation of logic.<br>Easy to add more operations like ExportVisitor, ThemeApplierVisitor, etc.</blockquote><h3>Pros &amp; Cons of the Visitor Pattern</h3><h4>✅ Pros</h4><ul><li>Easy to add new operations without changing existing classes</li><li>Keeps view/model classes clean and focused</li><li>Encourages separation of concerns</li><li>Centralizes complex operations (e.g., logging, exporting, theming)</li></ul><h4>❌ Cons</h4><ul><li>Harder to add new element types — requires updating all visitors</li><li>Can introduce boilerplate in large hierarchies</li><li>Might feel overkill for simple object models</li></ul><h3>6. So… Visitor or Kotlin Sealed Classes?</h3><p>If you’re already deep into Kotlin and your operations are limited and local, sealed classes + when is usually cleaner and faster. But in large, extensible, or Java-heavy projects, Visitor is still a solid architectural choice</p><h3>🧩 Final Thoughts</h3><p>The <strong>Visitor Pattern isn’t for everyday use</strong>, but in the right context — especially with legacy code, analytics, or SDK integrations — it’s a <strong>powerful, flexible tool</strong> that helps keep your code modular and clean.</p><p>If you ever find yourself writing dozens of when blocks to operate over different UI or model types…<br> …it might be time to send in a visitor. 😄</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=518c44dcc3d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>