<?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 Eizinhtay on Medium]]></title>
        <description><![CDATA[Stories by Eizinhtay on Medium]]></description>
        <link>https://medium.com/@eizinhtay1116?source=rss-f9f3f1c55067------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Ca4YMCo_R-wxRNO-.jpg</url>
            <title>Stories by Eizinhtay on Medium</title>
            <link>https://medium.com/@eizinhtay1116?source=rss-f9f3f1c55067------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 09:10:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@eizinhtay1116/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[ Kotlin Tip: Understanding Sealed Classes ]]></title>
            <link>https://medium.com/@eizinhtay1116/kotlin-tip-understanding-sealed-classes-61bd759c6bb8?source=rss-f9f3f1c55067------2</link>
            <guid isPermaLink="false">https://medium.com/p/61bd759c6bb8</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[state-management]]></category>
            <category><![CDATA[sealed-classes]]></category>
            <dc:creator><![CDATA[Eizinhtay]]></dc:creator>
            <pubDate>Wed, 12 Mar 2025 04:49:08 GMT</pubDate>
            <atom:updated>2025-03-12T04:59:06.033Z</atom:updated>
            <content:encoded><![CDATA[<p>Sealed classes in Kotlin provide a powerful way to create clear, maintainable, and safe class hierarchies. Let’s explore how they can improve your code!</p><h3>🔹 What Are Sealed Classes?</h3><p>Sealed classes allow you to define a restricted set of subclasses, ensuring exhaustive type checking and reducing potential errors. When used with when expressions, Kotlin enforces compile-time checks, eliminating the need for an else branch:</p><h4>✅ Using a Sealed Class (Exhaustive Checking)</h4><pre>sealed class Expr {<br>    data class Num(val value: Int) : Expr()<br>    data class Sum(val left: Expr, val right: Expr) : Expr()<br>}</pre><pre>fun eval(e: Expr): Int = when (e) {<br>    is Expr.Num -&gt; e.value<br>    is Expr.Sum -&gt; eval(e.left) + eval(e.right)<br>}</pre><pre>fun main() {<br>    val expression = Expr.Sum(Expr.Num(3), Expr.Num(5))<br>    println(&quot;Result: ${eval(expression)}&quot;) // Output: Result: 8<br>}</pre><p><strong>No risk</strong> of missing a case because Kotlin <strong>forces</strong> us to handle all subclasses. If a new subclass is added, the compiler will require it to be handled in the when expression.</p><h4>❌ Without a Sealed Class (No Exhaustive Checking)</h4><pre>open class Expr  <br>class Num(val value: Int) : Expr()  <br>class Sum(val left: Expr, val right: Expr) : Expr()  </pre><pre>fun eval(e: Expr): Int = when (e) {  <br>    is Num -&gt; e.value  <br>    is Sum -&gt; eval(e.left) + eval(e.right)  <br>    // Compiler won&#39;t warn if we forget to handle a new subclass<br>    else -&gt; throw IllegalArgumentException(&quot;Unknown type&quot;)<br>}</pre><p>If we add another subclass, there’s no <strong>compile-time</strong> enforcement to update the when expression. The else branch is necessary to avoid runtime errors.</p><h3>🎯 Why Use Sealed Classes?</h3><p>✅ Eliminates the need for default (else) branches, making code safer.<br> ✅ Ensures all subclasses are explicitly accounted for.<br> ✅ Improves maintainability—adding a new subclass prompts a compile-time check.</p><p>Sealed classes are perfect for representing <strong>state management</strong>, <strong>event handling</strong>, and <strong>API response modeling</strong> in Kotlin applications.</p><p>Have you used sealed classes in your projects? Share your thoughts in the comments! 👇</p><p>#Kotlin #SealedClasses #Programming #CleanCode #SoftwareDevelopment #AndroidDev #CodingTips</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61bd759c6bb8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Visibility Modifiers in Kotlin: A Quick Guide]]></title>
            <link>https://medium.com/@eizinhtay1116/visibility-modifiers-in-kotlin-a-quick-guide-9b88e1b8e2b3?source=rss-f9f3f1c55067------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b88e1b8e2b3</guid>
            <dc:creator><![CDATA[Eizinhtay]]></dc:creator>
            <pubDate>Sun, 09 Mar 2025 11:31:40 GMT</pubDate>
            <atom:updated>2025-03-09T11:31:40.636Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Visibility Modifiers in Kotlin: A Quick Guide</strong></p><p>In Kotlin, visibility modifiers control the accessibility of classes, methods, and top-level declarations. Here’s a brief overview:</p><ol><li><strong>Public (Default)</strong>:</li></ol><ul><li>By default, Kotlin declarations are public.</li><li>Accessible from anywhere within your project and other modules.</li></ul><pre>// Public by default<br>class MyPublicClass {<br>    fun publicMethod() {}<br>}</pre><ol><li><strong>Internal Visibility</strong>:</li></ol><ul><li>Internal declarations are visible only within the same module.</li><li>Provides encapsulation at the module level, effectively hiding implementation details.</li></ul><pre>internal class MyInternalClass {<br>    fun internalMethod() {}<br>}</pre><ol><li><strong>Private Visibility:</strong></li></ol><ul><li>Limits visibility strictly within the same Kotlin file or class.</li><li>Ensures maximum encapsulation, preventing accidental access or modification from outside.</li></ul><pre>class MyClass {<br>    private fun privateMethod() {}<br>}</pre><ol><li><strong>Protected Visibility:</strong></li></ol><ul><li>Visible in the same class and its subclasses.</li></ul><pre>open class MyBaseClass {<br>    protected fun protectedMethod() {}<br>}</pre><pre>class MySubClass : MyBaseClass() {<br>    fun accessProtected() {<br>        protectedMethod() // accessible here<br>    }<br>}</pre><p><strong>Why Internal?</strong></p><ul><li>Using internal visibility ensures true encapsulation within your module.</li><li>Ideal for hiding implementation specifics, making your codebase more maintainable and secure.</li></ul><p>Remember, Kotlin does not utilize package-level visibility control, unlike Java. Visibility control in Kotlin is handled explicitly through modifiers (public, private, protected, and internal).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b88e1b8e2b3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>