<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Kotlin on Aamer Paul</title>
    <link>https://aamernabi.github.io/tags/kotlin/</link>
    <description>Recent content in Kotlin on Aamer Paul</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Sat, 02 Aug 2025 08:53:20 +0530</lastBuildDate>
    <atom:link href="https://aamernabi.github.io/tags/kotlin/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Strategy Pattern in Action</title>
      <link>https://aamernabi.github.io/posts/strategy-design-pattern-with-example/</link>
      <pubDate>Sat, 02 Aug 2025 08:53:20 +0530</pubDate>
      <guid>https://aamernabi.github.io/posts/strategy-design-pattern-with-example/</guid>
      <description>&lt;p&gt;&lt;strong&gt;Strategy Pattern&lt;/strong&gt; is a behavioral design pattern that enables selecting an algorithm’s behavior at runtime.&lt;/p&gt;&#xA;&lt;p&gt;It&amp;rsquo;s widely used and very flexible, perfect for cases where you want to avoid complex &lt;code&gt;if-else&lt;/code&gt; or &lt;code&gt;switch&lt;/code&gt; statements.&lt;/p&gt;&#xA;&lt;h3 id=&#34;use-cases&#34;&gt;Use cases&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;You want to replace conditionals (&lt;code&gt;if-else&lt;/code&gt; or &lt;code&gt;switch&lt;/code&gt;) with &lt;strong&gt;polymorphism&lt;/strong&gt;.&lt;/li&gt;&#xA;&lt;li&gt;You need to switch behavior at runtime or make it configurable. Example: User selecting payment option&lt;/li&gt;&#xA;&lt;li&gt;You want to define multiple ways of doing something (e.g., sorting, compression, payment).&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h3 id=&#34;core-concepts&#34;&gt;Core Concepts&lt;/h3&gt;&#xA;&lt;p&gt;The pattern consists of three main components:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Builder Design Pattern</title>
      <link>https://aamernabi.github.io/posts/builder-design-pattern/</link>
      <pubDate>Mon, 28 Jul 2025 18:30:20 +0530</pubDate>
      <guid>https://aamernabi.github.io/posts/builder-design-pattern/</guid>
      <description>&lt;p&gt;The &lt;strong&gt;Builder Design Pattern&lt;/strong&gt; is a creational design pattern that lets you construct complex objects step by step. Using Builder pattern you can use same construction process to can create different representations.&lt;/p&gt;&#xA;&lt;h3 id=&#34;use-case&#34;&gt;Use case&lt;/h3&gt;&#xA;&lt;p&gt;Use the Builder Pattern when:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;An object has many &lt;strong&gt;optional fields or configurations&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;You want to avoid constructor telescoping (i.e., too many overloaded constructors).&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;You need to create &lt;strong&gt;immutable objects&lt;/strong&gt; step by step.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-java&#34; data-lang=&#34;java&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;User&lt;/span&gt; {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;private&lt;/span&gt; String firstName;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;private&lt;/span&gt; String lastName;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;private&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;int&lt;/span&gt; age;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;private&lt;/span&gt; String email;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;private&lt;/span&gt; String phone;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;User&lt;/span&gt;(String firstName, String lastName) { ... }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;User&lt;/span&gt;(String firstName, String lastName, &lt;span style=&#34;color:#66d9ef&#34;&gt;int&lt;/span&gt; age) { ... }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;User&lt;/span&gt;(String firstName, String lastName, &lt;span style=&#34;color:#66d9ef&#34;&gt;int&lt;/span&gt; age, String email) { ... }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#75715e&#34;&gt;// ...&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In above example, you can see &lt;code&gt;User&lt;/code&gt; class is hard to maintain and read.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Factory and Abstract Factory Design Pattern</title>
      <link>https://aamernabi.github.io/posts/factory-design-pattern/</link>
      <pubDate>Sun, 27 Jul 2025 10:51:59 +0530</pubDate>
      <guid>https://aamernabi.github.io/posts/factory-design-pattern/</guid>
      <description>&lt;h2 id=&#34;factory-design-pattern&#34;&gt;Factory Design Pattern&lt;/h2&gt;&#xA;&lt;p&gt;&lt;strong&gt;Factory Pattern&lt;/strong&gt; is &lt;strong&gt;creational pattern&lt;/strong&gt; that delegate the instantiation of objects to a &lt;strong&gt;separate method or class&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;The Factory design pattern provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that&amp;rsquo;ll be created. This pattern helps to decouple the client code from the concrete classes it needs to instantiate.&lt;/p&gt;&#xA;&lt;h3 id=&#34;core-components&#34;&gt;Core Components&lt;/h3&gt;&#xA;&lt;p&gt;The Factory pattern has three main components:&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
