<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Dionis</title>
    <description>The latest articles on DEV Community by Dionis (@dionisuliu).</description>
    <link>https://dev.to/dionisuliu</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F909084%2Fedcdcdd5-e0d0-47ff-a0a6-10bebed025dd.jpeg</url>
      <title>DEV Community: Dionis</title>
      <link>https://dev.to/dionisuliu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dionisuliu"/>
    <language>en</language>
    <item>
      <title>7 Design Patterns EVERY Developer Should Know</title>
      <dc:creator>Dionis</dc:creator>
      <pubDate>Mon, 10 Feb 2025 11:03:42 +0000</pubDate>
      <link>https://dev.to/dionisuliu/7-design-patterns-every-developer-should-know-3koh</link>
      <guid>https://dev.to/dionisuliu/7-design-patterns-every-developer-should-know-3koh</guid>
      <description>&lt;p&gt;Today, you'll explore seven different software design patterns—many of which you may already use without even realizing it. These patterns provide proven solutions to recurring programming challenges, regardless of the language or platform. In essence, a design pattern is a reusable template for solving common software engineering problems.  &lt;/p&gt;

&lt;p&gt;In 1994, four developers, now known as the Gang of Four, documented, categorized, and formalized 23 widely used design patterns in their influential book. This book remains highly relevant today, and I strongly recommend reading it. All these patterns are grouped into three main categories.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creational patterns&lt;/strong&gt; | &lt;strong&gt;Structural patterns&lt;/strong&gt; | &lt;strong&gt;Behavioral patterns&lt;/strong&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Creational patterns&lt;/strong&gt; are all about how objects are created. Instead of just instantiating objects directly, these patterns give you more flexibility and control over the process. Think of it like ordering a pizza—you don’t just throw ingredients together. You might pick a preset option from the menu (Factory pattern) or customize it step by step (Builder pattern).  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Structural patterns&lt;/strong&gt; focus on how objects are organized and connected. They help you build larger, more complex structures out of smaller, simpler pieces. Imagine building something out of LEGO. A massive Death Star set has thousands of pieces, but the instruction manual breaks it down into small, manageable steps, making it easier to put together.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Behavioral patterns&lt;/strong&gt; deal with how objects communicate and work together. They define how responsibilities are distributed and how different parts of your code interact. One of the most useful is the Strategy pattern. Think of it like switching between navigation apps—Google Maps for driving, AllTrails for hiking, and Transit for public transportation. They all help you get from point A to point B, but they use different strategies to do it.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔂 The Singleton Pattern
&lt;/h2&gt;

&lt;p&gt;At its core, the Singleton Pattern is all about &lt;strong&gt;ensuring that there is only ONE instance of a class&lt;/strong&gt; and providing a &lt;strong&gt;global point of access&lt;/strong&gt; to it. That’s it. Instead of allowing multiple objects of a class to be created, the Singleton pattern makes sure that only one exists throughout the program’s lifecycle.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Why Would You Need This?
&lt;/h3&gt;

&lt;p&gt;Imagine you’re building an application that has a &lt;strong&gt;logging system&lt;/strong&gt;. You don’t want multiple instances of the logger floating around because that could lead to weird issues like duplicate log entries or inconsistent logging states. Instead, you want just &lt;strong&gt;one logger instance&lt;/strong&gt; that the entire application shares.  &lt;/p&gt;

&lt;p&gt;Or think about a &lt;strong&gt;database connection manager&lt;/strong&gt;—you wouldn’t want your app to create a new database connection every time it needs to query something. That would be a nightmare for performance. A Singleton ensures that only &lt;strong&gt;one connection manager exists&lt;/strong&gt;, which everything else in your app can use.  &lt;/p&gt;

&lt;h3&gt;
  
  
  How Does It Work?
&lt;/h3&gt;

&lt;p&gt;To enforce the Singleton behavior, we usually do three things in our class:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Make the constructor private&lt;/strong&gt; → So no one outside the class can create a new instance.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Create a static instance of the class&lt;/strong&gt; → This is the single instance that will be shared.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Provide a public static method to get the instance&lt;/strong&gt; → This method checks if the instance exists; if not, it creates one.
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  The Singleton Pattern in Code (TypeScript Example)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Singleton&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nx"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Singleton&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Step 2: Private constructor so it can't be instantiated outside&lt;/span&gt;
  &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

  &lt;span class="c1"&gt;// Step 3: Public method to return the single instance&lt;/span&gt;
  &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nf"&gt;getInstance&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nx"&gt;Singleton&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;Singleton&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// If no instance exists, create one&lt;/span&gt;
      &lt;span class="nx"&gt;Singleton&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Singleton&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;Singleton&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello from Singleton!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Usage example&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;singleton1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Singleton&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getInstance&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;singleton2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Singleton&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getInstance&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;singleton1&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;singleton2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true (same instance)&lt;/span&gt;
&lt;span class="nx"&gt;singleton1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: Hello from Singleton!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this setup, every time you call &lt;code&gt;Singleton.getInstance()&lt;/code&gt;, you’ll always get the same instance of the class.  &lt;/p&gt;

&lt;h3&gt;
  
  
  But Wait… What About Multithreading?
&lt;/h3&gt;

&lt;p&gt;JavaScript (and TypeScript) are &lt;strong&gt;single-threaded&lt;/strong&gt;, so we don’t have to worry about race conditions like we do in Java. However, if your Singleton is handling asynchronous operations (like database connections), you &lt;strong&gt;might still need to ensure thread safety&lt;/strong&gt; using something like &lt;strong&gt;locks&lt;/strong&gt; or &lt;strong&gt;promises&lt;/strong&gt;.  &lt;/p&gt;

&lt;h3&gt;
  
  
  The Eager Initialization Approach (Safer but Less Efficient)
&lt;/h3&gt;

&lt;p&gt;Another way to make the Singleton &lt;strong&gt;safer&lt;/strong&gt; is to &lt;strong&gt;create the instance at the very beginning&lt;/strong&gt;, instead of waiting for &lt;code&gt;getInstance()&lt;/code&gt; to be called.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Singleton&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nx"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Singleton&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Singleton&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Eager initialization&lt;/span&gt;

  &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

  &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nf"&gt;getInstance&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nx"&gt;Singleton&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;Singleton&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Just return the already-created instance&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This method is thread-safe and &lt;strong&gt;doesn’t require any condition checks&lt;/strong&gt;, but the downside is that the instance is created &lt;strong&gt;even if it’s never used&lt;/strong&gt;.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Real-world Examples of the Singleton Pattern
&lt;/h3&gt;

&lt;p&gt;So where is this actually used?&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Database connection managers&lt;/strong&gt; – Only one connection pool should exist.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Logging frameworks&lt;/strong&gt; – A single logger instance handles all logs.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Configuration managers&lt;/strong&gt; – You don’t want multiple versions of your app’s settings.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Thread pools&lt;/strong&gt; – A single pool manages threads efficiently.  &lt;/p&gt;
&lt;h3&gt;
  
  
  When NOT to Use Singleton
&lt;/h3&gt;

&lt;p&gt;While Singleton is useful, it’s not always the best choice. Some developers even avoid it because:&lt;br&gt;&lt;br&gt;
❌ It introduces &lt;strong&gt;global state&lt;/strong&gt;, which can make debugging harder.&lt;br&gt;&lt;br&gt;
❌ It can lead to &lt;strong&gt;tight coupling&lt;/strong&gt;, making your code less flexible.&lt;br&gt;&lt;br&gt;
❌ It’s hard to &lt;strong&gt;unit test&lt;/strong&gt; since you can’t easily mock it. &lt;/p&gt;


&lt;h2&gt;
  
  
  🏗️ The Builder Pattern
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;Builder Pattern&lt;/strong&gt; is a &lt;strong&gt;creational design pattern&lt;/strong&gt; that helps you construct &lt;strong&gt;complex objects step by step&lt;/strong&gt;. Instead of having &lt;strong&gt;one giant constructor&lt;/strong&gt; with tons of parameters, you use a &lt;strong&gt;builder class&lt;/strong&gt; to &lt;strong&gt;gradually build&lt;/strong&gt; an object by calling methods that set properties one by one.  &lt;/p&gt;

&lt;p&gt;Think of it like ordering a &lt;strong&gt;custom burger&lt;/strong&gt; at a restaurant:&lt;br&gt;&lt;br&gt;
🍔 Instead of choosing from a few predefined options, you &lt;strong&gt;build&lt;/strong&gt; your burger step by step:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add cheese 🧀
&lt;/li&gt;
&lt;li&gt;Add lettuce 🥬
&lt;/li&gt;
&lt;li&gt;Add bacon 🥓
&lt;/li&gt;
&lt;li&gt;Choose your sauce 🥫
&lt;/li&gt;
&lt;li&gt;Done! ✅
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;strong&gt;Builder Pattern&lt;/strong&gt; works the same way—you construct an object by &lt;strong&gt;chaining methods&lt;/strong&gt; until you're happy with the final result.  &lt;/p&gt;



&lt;p&gt;Why Would You Need This?&lt;br&gt;&lt;br&gt;
Let’s say you're creating a &lt;code&gt;Car&lt;/code&gt; object. Without the Builder Pattern, you might end up with &lt;strong&gt;a huge constructor&lt;/strong&gt; like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;brand&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;engine&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;wheels&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myCar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Toyota&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Auris&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Red&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hybrid&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🤯 That’s &lt;strong&gt;a lot of parameters&lt;/strong&gt; in one place, and if you ever need to &lt;strong&gt;add more&lt;/strong&gt;, it quickly becomes &lt;strong&gt;hard to manage&lt;/strong&gt;.  &lt;/p&gt;

&lt;p&gt;Instead, the Builder Pattern lets you &lt;strong&gt;gradually&lt;/strong&gt; create the object &lt;strong&gt;in a readable and flexible way&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  The Builder Pattern in Code (TypeScript Example)
&lt;/h3&gt;

&lt;h4&gt;
  
  
  ✅ &lt;strong&gt;Step 1: Create the &lt;code&gt;Car&lt;/code&gt; class (The Product)&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;This is the object we want to &lt;strong&gt;build&lt;/strong&gt; step by step.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;brand&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;model&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;engine&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;wheels&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;showDetails&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Car Details: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;brand&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;, Color: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;, Engine: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;engine&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;, Wheels: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;wheels&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  ✅ &lt;strong&gt;Step 2: Create the &lt;code&gt;CarBuilder&lt;/code&gt; class (The Builder)&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;This class will provide &lt;strong&gt;chained methods&lt;/strong&gt; to set values &lt;strong&gt;one by one&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CarBuilder&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;car&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;car&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Start with an empty Car object&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;setBrand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;brand&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;CarBuilder&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;brand&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;brand&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Return `this` to allow method chaining&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;setModel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;CarBuilder&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;setColor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;CarBuilder&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;setEngine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;engine&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;CarBuilder&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;engine&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;engine&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;setWheels&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;wheels&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;CarBuilder&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;wheels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;wheels&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;build&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nx"&gt;Car&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;car&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Return the fully built Car object&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  ✅ &lt;strong&gt;Step 3: Use the Builder to Create Objects Easily&lt;/strong&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myCar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;CarBuilder&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setBrand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Toyota&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setModel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Auris&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setColor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Red&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setEngine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hybrid&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setWheels&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;build&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;myCar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;showDetails&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: Car Details: Toyota Auris, Color: Red, Engine: Hybrid, Wheels: 4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, instead of using a &lt;strong&gt;huge constructor&lt;/strong&gt;, we can &lt;strong&gt;gradually&lt;/strong&gt; set values in a clear and structured way.  &lt;/p&gt;




&lt;h3&gt;
  
  
  Advantages of the Builder Pattern
&lt;/h3&gt;

&lt;p&gt;✅ &lt;strong&gt;Improves readability&lt;/strong&gt; – No more long constructors with 10+ parameters.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;More flexibility&lt;/strong&gt; – You can &lt;strong&gt;skip optional properties&lt;/strong&gt; without overloading constructors.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Encapsulates object creation&lt;/strong&gt; – Keeps your code cleaner and easier to maintain.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Method chaining&lt;/strong&gt; – Lets you build an object step by step in a natural way.  &lt;/p&gt;


&lt;h3&gt;
  
  
  Real-World Examples of the Builder Pattern
&lt;/h3&gt;

&lt;p&gt;Where do we actually see this pattern in use?&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Configuring HTTP Requests&lt;/strong&gt; (&lt;code&gt;fetch&lt;/code&gt; API with chaining methods)&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Building complex UI components&lt;/strong&gt; (Fluent UI in React, Builder pattern in Angular)&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Game development&lt;/strong&gt; (Character or level builders)&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Creating SQL queries&lt;/strong&gt; (&lt;code&gt;QueryBuilder&lt;/code&gt; in TypeORM)  &lt;/p&gt;


&lt;h3&gt;
  
  
  When NOT to Use the Builder Pattern
&lt;/h3&gt;

&lt;p&gt;❌ If your object is &lt;strong&gt;simple&lt;/strong&gt;, using a builder adds unnecessary complexity.&lt;br&gt;&lt;br&gt;
❌ If the object's properties are &lt;strong&gt;fixed and don't change often&lt;/strong&gt;, a normal constructor is fine.&lt;br&gt;&lt;br&gt;
❌ If performance is a concern, &lt;strong&gt;builders create extra objects&lt;/strong&gt; before the final one is returned. &lt;/p&gt;


&lt;h2&gt;
  
  
  🏭 The Factory Pattern
&lt;/h2&gt;

&lt;p&gt;Imagine you run a &lt;strong&gt;pizza shop&lt;/strong&gt;. Instead of letting customers randomly mix ingredients and create messy orders, you provide a &lt;strong&gt;menu&lt;/strong&gt; where they can choose specific types of pizza.  &lt;/p&gt;

&lt;p&gt;In programming, the Factory Pattern works the same way:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Instead of letting users manually create objects, we provide a &lt;strong&gt;factory method&lt;/strong&gt; that returns the correct object based on some input.
&lt;/li&gt;
&lt;li&gt;This improves flexibility and &lt;strong&gt;decouples&lt;/strong&gt; object creation from the main code.
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Why Use the Factory Pattern?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Simplifies object creation&lt;/strong&gt; – No need to use &lt;code&gt;new&lt;/code&gt; all over the place.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Encapsulates logic&lt;/strong&gt; – If the way objects are created changes, you only update the factory, not the entire codebase.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Improves maintainability&lt;/strong&gt; – Makes the code cleaner and easier to manage.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Supports polymorphism&lt;/strong&gt; – A single factory can create different types of related objects.
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Factory Pattern in Code (TypeScript Example)
&lt;/h3&gt;
&lt;h4&gt;
  
  
  ✅ &lt;strong&gt;Step 1: Create an Interface for Products&lt;/strong&gt;
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Vehicle&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;drive&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This ensures that all vehicles (cars, bikes, etc.) have a &lt;code&gt;drive()&lt;/code&gt; method.  &lt;/p&gt;
&lt;h4&gt;
  
  
  ✅ &lt;strong&gt;Step 2: Create Concrete Classes (Products)&lt;/strong&gt;
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;Vehicle&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;drive&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Driving a car 🚗&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Bike&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;Vehicle&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;drive&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Riding a bike 🚴&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Each vehicle implements the &lt;code&gt;Vehicle&lt;/code&gt; interface.  &lt;/p&gt;
&lt;h4&gt;
  
  
  ✅ &lt;strong&gt;Step 3: Create the Factory Class&lt;/strong&gt;
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;VehicleFactory&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nf"&gt;createVehicle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;Vehicle&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;car&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bike&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Bike&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Unknown vehicle type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Instead of using &lt;code&gt;new Car()&lt;/code&gt; or &lt;code&gt;new Bike()&lt;/code&gt;, we call &lt;code&gt;VehicleFactory.createVehicle(type)&lt;/code&gt;, and it &lt;strong&gt;decides which object to return&lt;/strong&gt;.  &lt;/p&gt;
&lt;h4&gt;
  
  
  ✅ &lt;strong&gt;Step 4: Use the Factory to Create Objects&lt;/strong&gt;
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myCar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;VehicleFactory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createVehicle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;car&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;myCar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;drive&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: Driving a car 🚗&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myBike&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;VehicleFactory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createVehicle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bike&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;myBike&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;drive&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: Riding a bike 🚴&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Advantages of the Factory Pattern
&lt;/h3&gt;

&lt;p&gt;✅ &lt;strong&gt;Encapsulates object creation&lt;/strong&gt; – No need to worry about how objects are created.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Easier maintenance&lt;/strong&gt; – If a new vehicle type is added, we only modify the factory.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Supports polymorphism&lt;/strong&gt; – The calling code doesn’t need to know the exact class.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Removes code duplication&lt;/strong&gt; – Avoids repeated &lt;code&gt;new&lt;/code&gt; object creation across the app.  &lt;/p&gt;
&lt;h3&gt;
  
  
  Real-World Examples of the Factory Pattern
&lt;/h3&gt;

&lt;p&gt;✅ &lt;strong&gt;Database connections&lt;/strong&gt; – A factory selects the correct database driver (MySQL, PostgreSQL, etc.).&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;UI component creation&lt;/strong&gt; – A factory generates buttons, dropdowns, or checkboxes dynamically.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Logging systems&lt;/strong&gt; – A factory determines whether to log to a file, database, or console.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Payment processing&lt;/strong&gt; – A factory creates instances of different payment gateways (PayPal, Stripe, etc.).  &lt;/p&gt;
&lt;h3&gt;
  
  
  When NOT to Use the Factory Pattern
&lt;/h3&gt;

&lt;p&gt;❌ If object creation is &lt;strong&gt;simple&lt;/strong&gt;, the factory adds unnecessary complexity.&lt;br&gt;&lt;br&gt;
❌ If there are &lt;strong&gt;no plans for multiple object types&lt;/strong&gt;, a factory is overkill.&lt;br&gt;&lt;br&gt;
❌ If performance is critical, a factory &lt;strong&gt;may slow things down&lt;/strong&gt; due to extra function calls.  &lt;/p&gt;


&lt;h2&gt;
  
  
  🎭 The Facade Pattern
&lt;/h2&gt;

&lt;p&gt;Imagine you’re in a &lt;strong&gt;hotel&lt;/strong&gt;. Instead of calling the &lt;strong&gt;chef, housekeeping, and maintenance separately&lt;/strong&gt;, you just call the &lt;strong&gt;reception desk&lt;/strong&gt;, and they handle everything for you.  &lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Facade Pattern&lt;/strong&gt; works the same way:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It &lt;strong&gt;hides complexity&lt;/strong&gt; by exposing a &lt;strong&gt;simple API&lt;/strong&gt;.
&lt;/li&gt;
&lt;li&gt;It delegates tasks to underlying components &lt;strong&gt;without exposing&lt;/strong&gt; their details.
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Why Use the Facade Pattern?
&lt;/h3&gt;

&lt;p&gt;✅ &lt;strong&gt;Simplifies usage&lt;/strong&gt; – Clients don’t need to understand the entire system.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Reduces dependencies&lt;/strong&gt; – Clients interact with only one interface.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Improves maintainability&lt;/strong&gt; – Changes in subsystems don’t affect the client.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Encapsulates complexity&lt;/strong&gt; – Internal details remain hidden.  &lt;/p&gt;
&lt;h3&gt;
  
  
  Facade Pattern in Code (TypeScript Example)
&lt;/h3&gt;
&lt;h4&gt;
  
  
  ✅ &lt;strong&gt;Step 1: Create Complex Subsystems&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;These are the classes that perform different tasks, but they are &lt;strong&gt;not directly accessed by the client&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AudioSystem&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;turnOn&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Audio system is ON 🎵&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;setVolume&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;level&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Volume set to &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;level&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Projector&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;turnOn&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Projector is ON 📽️&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;setInput&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;source&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Projector input set to &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;source&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;StreamingService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;playMovie&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;movie&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Streaming movie: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;movie&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; 🎬`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each of these &lt;strong&gt;subsystems&lt;/strong&gt; has its own methods, which makes it &lt;strong&gt;complicated&lt;/strong&gt; to use them all together.  &lt;/p&gt;

&lt;h4&gt;
  
  
  ✅ &lt;strong&gt;Step 2: Create the Facade Class&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The &lt;strong&gt;Facade&lt;/strong&gt; simplifies interaction by exposing a single method that hides the complexity.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;HomeTheaterFacade&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;audio&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;AudioSystem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;projector&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Projector&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;streaming&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;StreamingService&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;audio&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;AudioSystem&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;projector&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Projector&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;streaming&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;StreamingService&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;startMovie&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;movie&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Starting movie night... 🍿&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;audio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;turnOn&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;audio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setVolume&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;projector&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;turnOn&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;projector&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setInput&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;HDMI&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;streaming&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;playMovie&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;movie&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  ✅ &lt;strong&gt;Step 3: Use the Facade&lt;/strong&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;homeTheater&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;HomeTheaterFacade&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;homeTheater&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startMovie&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Inception&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Starting movie night... 🍿
Audio system is ON 🎵
Volume set to 10
Projector is ON 📽️
Projector input set to HDMI
Streaming movie: Inception 🎬
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of manually controlling each system, we &lt;strong&gt;only call one method&lt;/strong&gt; (&lt;code&gt;startMovie()&lt;/code&gt;), and the facade takes care of the rest.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Advantages of the Facade Pattern
&lt;/h3&gt;

&lt;p&gt;✅ &lt;strong&gt;Simplifies the interface&lt;/strong&gt; – Clients don’t need to deal with multiple subsystems.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Encapsulates complexity&lt;/strong&gt; – Changes inside subsystems don’t affect clients.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Reduces dependencies&lt;/strong&gt; – Clients only depend on the Facade, not individual classes.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Improves maintainability&lt;/strong&gt; – Easier to update a single Facade than multiple classes.  &lt;/p&gt;
&lt;h3&gt;
  
  
  Real-World Examples of the Facade Pattern
&lt;/h3&gt;

&lt;p&gt;✅ &lt;strong&gt;Operating Systems&lt;/strong&gt; – Instead of calling low-level system APIs, we use a simple UI.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Database Access&lt;/strong&gt; – ORM libraries like TypeORM simplify raw SQL queries.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Media Players&lt;/strong&gt; – Clicking "Play" hides the complexity of codecs and rendering.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Third-Party API Wrappers&lt;/strong&gt; – Stripe SDK hides complex payment APIs.  &lt;/p&gt;
&lt;h3&gt;
  
  
  When NOT to Use the Facade Pattern
&lt;/h3&gt;

&lt;p&gt;❌ If the system is &lt;strong&gt;already simple&lt;/strong&gt;, adding a Facade creates unnecessary overhead.&lt;br&gt;&lt;br&gt;
❌ If &lt;strong&gt;direct access&lt;/strong&gt; to subsystems is required for flexibility.&lt;br&gt;&lt;br&gt;
❌ If the Facade starts &lt;strong&gt;growing too large&lt;/strong&gt;, it can become a &lt;strong&gt;God Object&lt;/strong&gt; (doing too much).  &lt;/p&gt;


&lt;h2&gt;
  
  
  🔌 The Adapter Pattern - Structural patterns
&lt;/h2&gt;

&lt;p&gt;Imagine you buy a new &lt;strong&gt;laptop charger&lt;/strong&gt; in the U.S., but your power outlet is European. Instead of throwing away the charger, you buy a &lt;strong&gt;power adapter&lt;/strong&gt; that lets it fit into the European socket.  &lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Adapter Pattern&lt;/strong&gt; works the same way:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It &lt;strong&gt;converts&lt;/strong&gt; one interface into another that a client expects.
&lt;/li&gt;
&lt;li&gt;It allows two incompatible classes to &lt;strong&gt;work together&lt;/strong&gt;.
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Why Use the Adapter Pattern?
&lt;/h3&gt;

&lt;p&gt;✅ &lt;strong&gt;Allows code reuse&lt;/strong&gt; – You don’t have to modify existing classes.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Improves flexibility&lt;/strong&gt; – Works with third-party or legacy systems.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Encapsulates changes&lt;/strong&gt; – Any required adjustments stay within the adapter.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Promotes maintainability&lt;/strong&gt; – No need to rewrite entire systems for compatibility.  &lt;/p&gt;
&lt;h3&gt;
  
  
  Adapter Pattern in Code (TypeScript Example)
&lt;/h3&gt;
&lt;h4&gt;
  
  
  ✅ &lt;strong&gt;Step 1: Create an Incompatible Class&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;This is an &lt;strong&gt;existing class&lt;/strong&gt; that does not match the interface we need.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;OldCharger&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;chargeWithFlatPlug&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Charging with a flat plug ⚡&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The problem? It &lt;strong&gt;only supports flat plugs&lt;/strong&gt;, but we need a &lt;strong&gt;round plug&lt;/strong&gt; interface.  &lt;/p&gt;

&lt;h4&gt;
  
  
  ✅ &lt;strong&gt;Step 2: Define the Expected Interface&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;This is what the &lt;strong&gt;client&lt;/strong&gt; expects to use.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;RoundPlug&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;chargeWithRoundPlug&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;OldCharger&lt;/strong&gt; doesn’t support this interface, so we need an adapter.  &lt;/p&gt;

&lt;h4&gt;
  
  
  ✅ &lt;strong&gt;Step 3: Create the Adapter&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The &lt;strong&gt;adapter class&lt;/strong&gt; converts the old system (flat plug) into the expected interface (round plug).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ChargerAdapter&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;RoundPlug&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;oldCharger&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;OldCharger&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;oldCharger&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;OldCharger&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;oldCharger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;oldCharger&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;chargeWithRoundPlug&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Adapter converts round plug to flat plug...&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;oldCharger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;chargeWithFlatPlug&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, &lt;strong&gt;ChargerAdapter&lt;/strong&gt; acts as a &lt;strong&gt;middleman&lt;/strong&gt; between the incompatible plug types.  &lt;/p&gt;

&lt;h4&gt;
  
  
  ✅ &lt;strong&gt;Step 4: Use the Adapter&lt;/strong&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;oldCharger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;OldCharger&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;adapter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ChargerAdapter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;oldCharger&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;adapter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;chargeWithRoundPlug&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Adapter converts round plug to flat plug...
Charging with a flat plug ⚡
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even though the original charger only supports flat plugs, the adapter &lt;strong&gt;makes it work&lt;/strong&gt; with round plugs!  &lt;/p&gt;

&lt;h3&gt;
  
  
  Advantages of the Adapter Pattern
&lt;/h3&gt;

&lt;p&gt;✅ &lt;strong&gt;Enables compatibility&lt;/strong&gt; – Allows different systems to communicate.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Works with third-party code&lt;/strong&gt; – Adapts external libraries &lt;strong&gt;without modifying them&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Preserves existing code&lt;/strong&gt; – No need to rewrite or extend original classes.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Encapsulates complexity&lt;/strong&gt; – Keeps changes &lt;strong&gt;isolated&lt;/strong&gt; in the adapter.  &lt;/p&gt;
&lt;h3&gt;
  
  
  Real-World Examples of the Adapter Pattern
&lt;/h3&gt;

&lt;p&gt;✅ &lt;strong&gt;Power Adapters&lt;/strong&gt; – Convert plugs from one type to another.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Legacy System Integration&lt;/strong&gt; – Connects old APIs to modern interfaces.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Media Converters&lt;/strong&gt; – Adapts file formats (e.g., MP3 to WAV).&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Database Drivers&lt;/strong&gt; – Translates queries between different databases.  &lt;/p&gt;
&lt;h3&gt;
  
  
  When NOT to Use the Adapter Pattern
&lt;/h3&gt;

&lt;p&gt;❌ If you can &lt;strong&gt;modify the original class&lt;/strong&gt;, it's better than creating an adapter.&lt;br&gt;&lt;br&gt;
❌ If systems are &lt;strong&gt;already compatible&lt;/strong&gt;, the adapter adds unnecessary complexity.&lt;br&gt;&lt;br&gt;
❌ If using the &lt;strong&gt;Facade Pattern&lt;/strong&gt; makes more sense (when simplifying complex APIs).  &lt;/p&gt;


&lt;h2&gt;
  
  
  🎯 The Strategy Pattern
&lt;/h2&gt;

&lt;p&gt;Imagine you're using a &lt;strong&gt;navigation app&lt;/strong&gt; like Google Maps. Depending on your needs, you can choose:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Driving mode&lt;/strong&gt; 🚗 – Optimized for car routes.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cycling mode&lt;/strong&gt; 🚴 – Finds bike-friendly paths.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Walking mode&lt;/strong&gt; 🚶 – Shows pedestrian shortcuts.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;strong&gt;destination remains the same&lt;/strong&gt;, but the strategy (the route calculation method) changes. The &lt;strong&gt;Strategy Pattern&lt;/strong&gt; works the same way:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It allows a program to &lt;strong&gt;swap between different algorithms dynamically&lt;/strong&gt;.
&lt;/li&gt;
&lt;li&gt;The core logic (finding the route) remains unchanged, but the method used varies.
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Why Use the Strategy Pattern?
&lt;/h3&gt;

&lt;p&gt;✅ &lt;strong&gt;Encapsulates different behaviors&lt;/strong&gt; – No need for long &lt;code&gt;if-else&lt;/code&gt; statements.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Supports dynamic changes&lt;/strong&gt; – The strategy can be switched at runtime.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Encourages code reusability&lt;/strong&gt; – Different algorithms are kept in separate classes.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Improves maintainability&lt;/strong&gt; – Adding new strategies doesn’t require modifying existing code.  &lt;/p&gt;


&lt;h3&gt;
  
  
  Strategy Pattern in Code (TypeScript Example)
&lt;/h3&gt;
&lt;h4&gt;
  
  
  ✅ &lt;strong&gt;Step 1: Define a Common Interface&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Each strategy (algorithm) will implement this interface.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;PaymentStrategy&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;pay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  ✅ &lt;strong&gt;Step 2: Create Different Strategy Implementations&lt;/strong&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CreditCardPayment&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;PaymentStrategy&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;pay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Paid $&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; using Credit Card 💳`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PayPalPayment&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;PaymentStrategy&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;pay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Paid $&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; using PayPal 🏦`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CryptoPayment&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;PaymentStrategy&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;pay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Paid $&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; using Cryptocurrency ₿`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each class implements a different payment method.  &lt;/p&gt;

&lt;h4&gt;
  
  
  ✅ &lt;strong&gt;Step 3: Create a Context Class to Use Strategies&lt;/strong&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ShoppingCart&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;paymentMethod&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PaymentStrategy&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;paymentMethod&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PaymentStrategy&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;paymentMethod&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;paymentMethod&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;setPaymentMethod&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;paymentMethod&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PaymentStrategy&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;paymentMethod&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;paymentMethod&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;checkout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;paymentMethod&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  ✅ &lt;strong&gt;Step 4: Use the Strategy Pattern&lt;/strong&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cart&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ShoppingCart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;CreditCardPayment&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="nx"&gt;cart&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;checkout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: Paid  using Credit Card 💳&lt;/span&gt;

&lt;span class="nx"&gt;cart&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setPaymentMethod&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PayPalPayment&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="nx"&gt;cart&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;checkout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: Paid  using PayPal 🏦&lt;/span&gt;

&lt;span class="nx"&gt;cart&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setPaymentMethod&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;CryptoPayment&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="nx"&gt;cart&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;checkout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: Paid  using Cryptocurrency ₿&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Advantages of the Strategy Pattern
&lt;/h3&gt;

&lt;p&gt;✅ &lt;strong&gt;Flexible and Extensible&lt;/strong&gt; – New strategies can be added &lt;strong&gt;without modifying existing code&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Eliminates Large &lt;code&gt;if-else&lt;/code&gt; Statements&lt;/strong&gt; – Keeps code &lt;strong&gt;clean and readable&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Promotes Open/Closed Principle&lt;/strong&gt; – The system is open for extension but closed for modification.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Improves Testability&lt;/strong&gt; – Each strategy can be tested &lt;strong&gt;independently&lt;/strong&gt;.  &lt;/p&gt;
&lt;h3&gt;
  
  
  Real-World Examples of the Strategy Pattern
&lt;/h3&gt;

&lt;p&gt;✅ &lt;strong&gt;Sorting Algorithms&lt;/strong&gt; – Switching between QuickSort, MergeSort, BubbleSort, etc.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Payment Methods&lt;/strong&gt; – Credit Card, PayPal, Cryptocurrency, etc.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Compression Algorithms&lt;/strong&gt; – ZIP, RAR, GZIP, etc.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Authentication Mechanisms&lt;/strong&gt; – OAuth, JWT, Basic Auth, etc.  &lt;/p&gt;
&lt;h3&gt;
  
  
  When NOT to Use the Strategy Pattern
&lt;/h3&gt;

&lt;p&gt;❌ If there’s &lt;strong&gt;only one algorithm&lt;/strong&gt;, using the Strategy Pattern is unnecessary.&lt;br&gt;&lt;br&gt;
❌ If switching between strategies is &lt;strong&gt;never needed&lt;/strong&gt; in the application.&lt;br&gt;&lt;br&gt;
❌ If the extra complexity of multiple classes &lt;strong&gt;doesn’t justify&lt;/strong&gt; the benefits.  &lt;/p&gt;


&lt;h2&gt;
  
  
  👀 The Observer Pattern
&lt;/h2&gt;

&lt;p&gt;Think of a &lt;strong&gt;YouTube channel&lt;/strong&gt;:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When you &lt;strong&gt;subscribe&lt;/strong&gt; to a channel, you get notified of new videos.
&lt;/li&gt;
&lt;li&gt;If you &lt;strong&gt;unsubscribe&lt;/strong&gt;, you stop receiving updates.
&lt;/li&gt;
&lt;li&gt;The channel doesn’t know or care who its subscribers are—it just &lt;strong&gt;notifies everyone when something changes&lt;/strong&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;strong&gt;Observer Pattern&lt;/strong&gt; works the same way:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;subject&lt;/strong&gt; maintains a list of observers.
&lt;/li&gt;
&lt;li&gt;Observers can &lt;strong&gt;subscribe&lt;/strong&gt; or &lt;strong&gt;unsubscribe&lt;/strong&gt;.
&lt;/li&gt;
&lt;li&gt;When the subject’s state changes, it &lt;strong&gt;notifies all observers automatically&lt;/strong&gt;.
&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;
  
  
  Why Use the Observer Pattern?
&lt;/h3&gt;

&lt;p&gt;✅ &lt;strong&gt;Loosely coupled&lt;/strong&gt; – The subject and observers are independent.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Automatic updates&lt;/strong&gt; – Observers don’t need to constantly check for changes.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Extensible&lt;/strong&gt; – New observers can be added without modifying the subject.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Supports event-driven systems&lt;/strong&gt; – Useful for UI updates, notifications, etc.  &lt;/p&gt;


&lt;h3&gt;
  
  
  Observer Pattern in Code (TypeScript Example)
&lt;/h3&gt;
&lt;h4&gt;
  
  
  ✅ &lt;strong&gt;Step 1: Create the Observer Interface&lt;/strong&gt;
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Observer&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;All observers must implement the &lt;code&gt;update()&lt;/code&gt; method to receive notifications.  &lt;/p&gt;
&lt;h4&gt;
  
  
  ✅ &lt;strong&gt;Step 2: Create the Subject (Observable) Interface&lt;/strong&gt;
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Subject&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Observer&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;unsubscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Observer&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The &lt;strong&gt;subject&lt;/strong&gt; maintains a list of observers and notifies them of updates.  &lt;/p&gt;
&lt;h4&gt;
  
  
  ✅ &lt;strong&gt;Step 3: Implement the Concrete Subject&lt;/strong&gt;
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;YouTubeChannel&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;Subject&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;observers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Observer&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;

  &lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Observer&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;observers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Subscriber added! 🎉&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;unsubscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Observer&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;observers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;observers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sub&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;sub&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Subscriber removed! ❌&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Notifying subscribers: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;observers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;observer&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;uploadVideo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`New video uploaded: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; 📹`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`New video: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The &lt;strong&gt;YouTubeChannel&lt;/strong&gt; maintains a list of subscribers and notifies them when a new video is uploaded.  &lt;/p&gt;
&lt;h4&gt;
  
  
  ✅ &lt;strong&gt;Step 4: Implement Concrete Observers&lt;/strong&gt;
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;Observer&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

  &lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; received notification: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Each &lt;strong&gt;User&lt;/strong&gt; represents a subscriber who receives notifications.  &lt;/p&gt;
&lt;h4&gt;
  
  
  ✅ &lt;strong&gt;Step 5: Use the Observer Pattern&lt;/strong&gt;
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;channel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;YouTubeChannel&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Bob&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;channel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;channel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;channel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;uploadVideo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Observer Pattern Tutorial&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Notifies all subscribers&lt;/span&gt;

&lt;span class="nx"&gt;channel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;unsubscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;channel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;uploadVideo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Strategy Pattern Tutorial&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Only Bob gets notified&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Subscriber added! 🎉
Subscriber added! 🎉
New video uploaded: Observer Pattern Tutorial 📹
Notifying subscribers: New video: Observer Pattern Tutorial
Alice received notification: New video: Observer Pattern Tutorial
Bob received notification: New video: Observer Pattern Tutorial
Subscriber removed! ❌
New video uploaded: Strategy Pattern Tutorial 📹
Notifying subscribers: New video: Strategy Pattern Tutorial
Bob received notification: New video: Strategy Pattern Tutorial
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Advantages of the Observer Pattern
&lt;/h3&gt;

&lt;p&gt;✅ &lt;strong&gt;Decouples subjects from observers&lt;/strong&gt; – Subjects don’t need to know their observers.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Supports dynamic relationships&lt;/strong&gt; – Observers can subscribe or unsubscribe at runtime.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Ideal for event-driven systems&lt;/strong&gt; – Used in UI frameworks, messaging, and notifications.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Real-World Examples
&lt;/h3&gt;

&lt;p&gt;✅ &lt;strong&gt;Event Listeners in JavaScript&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Stock Market Trackers&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Weather Monitoring Systems&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Notification Systems&lt;/strong&gt;  &lt;/p&gt;

</description>
      <category>designpatterns</category>
      <category>programming</category>
      <category>typescript</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Git &amp; GitHub cheatsheet</title>
      <dc:creator>Dionis</dc:creator>
      <pubDate>Mon, 22 Aug 2022 10:18:00 +0000</pubDate>
      <link>https://dev.to/dionisuliu/git-cheatsheet-2l72</link>
      <guid>https://dev.to/dionisuliu/git-cheatsheet-2l72</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is Git&lt;/strong&gt;❓&lt;/p&gt;

&lt;p&gt;Git is a version control system used for tracking changes in computer files. It is generally used for source code management in software development.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Git is used to tracking changes in the source code&lt;/li&gt;
&lt;li&gt;The distributed version control tool is used for source code management&lt;/li&gt;
&lt;li&gt;It allows multiple developers to work together&lt;/li&gt;
&lt;li&gt;It supports non-linear development through its thousands of parallel branches&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  📸 &lt;strong&gt;&lt;em&gt;Creating Snapshots&lt;/em&gt;&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Initializing a repository&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Staging files&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git add file1.js            &lt;span class="c"&gt;# Stages a single file&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git add file1.js file2.js   &lt;span class="c"&gt;# Stages multiple files&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git add &lt;span class="k"&gt;*&lt;/span&gt;.js                &lt;span class="c"&gt;# Stages with a pattern&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git add &lt;span class="nb"&gt;.&lt;/span&gt;                   &lt;span class="c"&gt;# Stages the current directory and all its content&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Viewing the status&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git status                   &lt;span class="c"&gt;# Full status&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git status &lt;span class="nt"&gt;-s&lt;/span&gt;                &lt;span class="c"&gt;# Short status&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Committing the staged files&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; “Message”.     &lt;span class="c"&gt;# Commits with a one-line message&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git commit                   &lt;span class="c"&gt;# Opens the default editor to type a long message&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Skipping the staging area&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git commit &lt;span class="nt"&gt;-am&lt;/span&gt; “Message”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Removing files&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git &lt;span class="nb"&gt;rm &lt;/span&gt;file1.js              &lt;span class="c"&gt;# Removes from working directory and staging area&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;--cached&lt;/span&gt; file1.js.    &lt;span class="c"&gt;# Removes from staging area only&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Renaming or moving files&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git &lt;span class="nb"&gt;mv &lt;/span&gt;file1.js file1.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Viewing the staged/unstaged changes&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git diff                     &lt;span class="c"&gt;# Shows unstaged changes&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git diff &lt;span class="nt"&gt;--staged&lt;/span&gt;            &lt;span class="c"&gt;# Shows staged changes&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git diff &lt;span class="nt"&gt;--cached&lt;/span&gt;            &lt;span class="c"&gt;# Same as the above&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Viewing the history&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git log                      &lt;span class="c"&gt;# Full history&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git log &lt;span class="nt"&gt;--oneline&lt;/span&gt;            &lt;span class="c"&gt;# Summary&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git log &lt;span class="nt"&gt;--reverse&lt;/span&gt;            &lt;span class="c"&gt;# Lists the commits from the oldest to the newest&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Viewing a commit&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git show 921a2ff             &lt;span class="c"&gt;# Shows the given commit&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git show HEAD                &lt;span class="c"&gt;# Shows the last commit&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git show HEAD~2              &lt;span class="c"&gt;# Two steps before the last commit&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git show HEAD:file.js        &lt;span class="c"&gt;# Shows the version of file.js stored in the last             ...                              commit&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Unstaging files (undoing git add)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git restore &lt;span class="nt"&gt;--staged&lt;/span&gt; file.js   &lt;span class="c"&gt;# Copies the last version of file.js from repo ...                                to index&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Discarding local changes&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git restore file.js          &lt;span class="c"&gt;# Copies file.js from index to working directory&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git restore file1.js file2.js   &lt;span class="c"&gt;# Restores multiple files in working directory&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git restore &lt;span class="nb"&gt;.&lt;/span&gt;            &lt;span class="c"&gt;# Discards all local changes (except untracked files)&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git clean &lt;span class="nt"&gt;-fd&lt;/span&gt;            &lt;span class="c"&gt;# Removes all untracked files&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Restoring an earlier version of a file&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git restore &lt;span class="nt"&gt;--source&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;HEAD~2 file.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  📥 &lt;strong&gt;&lt;em&gt;Browsing History&lt;/em&gt;&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Viewing the history&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git log &lt;span class="nt"&gt;--stat&lt;/span&gt;           &lt;span class="c"&gt;# Shows the list of modified files&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git log &lt;span class="nt"&gt;--patch&lt;/span&gt;          &lt;span class="c"&gt;# Shows the actual changes (patches)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Filtering the history&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git log &lt;span class="nt"&gt;-3&lt;/span&gt;                             &lt;span class="c"&gt;# Shows the last 3 entries&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git log &lt;span class="nt"&gt;--author&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;“Mosh”
&lt;span class="nv"&gt;$ &lt;/span&gt;git log &lt;span class="nt"&gt;--before&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;“2020-08-17” 
&lt;span class="nv"&gt;$ &lt;/span&gt;git log &lt;span class="nt"&gt;--after&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;“one week ago”
&lt;span class="nv"&gt;$ &lt;/span&gt;git log &lt;span class="nt"&gt;--grep&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;“GUI”                   &lt;span class="c"&gt;# Commits with “GUI” in their message&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git log &lt;span class="nt"&gt;-S&lt;/span&gt;“GUI”                        &lt;span class="c"&gt;# Commits with “GUI” in their patches&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git log hash1..hash2                   &lt;span class="c"&gt;# Range of commits&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git log file.txt                       &lt;span class="c"&gt;# Commits that touched file.txt&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Formatting the log output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git log &lt;span class="nt"&gt;--pretty&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;format:”%an committed %H”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Creating an alias&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.lg “log &lt;span class="nt"&gt;--oneline&lt;/span&gt;&lt;span class="s2"&gt;"
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Viewing a commit&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git show HEAD~2
&lt;span class="nv"&gt;$ &lt;/span&gt;git show HEAD~2:file1.txt   &lt;span class="c"&gt;# Shows the version of file stored in this commit&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Comparing commits&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git diff HEAD~2 HEAD.             &lt;span class="c"&gt;# Shows the changes between two commits&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git diff HEAD~2 HEAD file.txt.    &lt;span class="c"&gt;# Changes to file.txt only&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Checking out a commit&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git checkout dad47ed                  &lt;span class="c"&gt;# Checks out the given commit&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git checkout master                   &lt;span class="c"&gt;# Checks out the master branch&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Finding a bad commit&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git bisect start
&lt;span class="nv"&gt;$ &lt;/span&gt;git bisect bad                     &lt;span class="c"&gt;# Marks the current commit as a bad commit&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git bisect good ca49180            &lt;span class="c"&gt;# Marks the given commit as a good commit&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git bisect reset                   &lt;span class="c"&gt;# Terminates the bisect session&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Finding contributors&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git shortlog
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Viewing the history of a file&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git log file.txt       &lt;span class="c"&gt;# Shows the commits that touched file.txt&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git log &lt;span class="nt"&gt;--stat&lt;/span&gt; file.tx &lt;span class="c"&gt;# Shows statistics (the number of changes) for file.txt&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git log &lt;span class="nt"&gt;--patch&lt;/span&gt; file.txt. &lt;span class="c"&gt;# Shows the patches (changes) applied to file.txt&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Finding the author of lines&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git blame file.txt         &lt;span class="c"&gt;# Shows the author of each line in file.txt&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Tagging&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git tag v1.0               &lt;span class="c"&gt;# Tags the last commit as v1.0&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git tag v1.0 5e7a828       &lt;span class="c"&gt;# Tags an earlier commit&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git tag                    &lt;span class="c"&gt;# Lists all the tags&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git tag &lt;span class="nt"&gt;-d&lt;/span&gt; v1.0            &lt;span class="c"&gt;# Deletes the given tag&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  🌿 &lt;strong&gt;&lt;em&gt;Branching &amp;amp; Merging&lt;/em&gt;&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Managing branches&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git branch bugfix           &lt;span class="c"&gt;# Creates a new branch called bugfix&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git checkout bugfix         &lt;span class="c"&gt;# Switches to the bugfix branch&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git switch bugfix           &lt;span class="c"&gt;# Same as the above&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git switch &lt;span class="nt"&gt;-C&lt;/span&gt; bugfix        &lt;span class="c"&gt;# Creates and switches&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git branch &lt;span class="nt"&gt;-d&lt;/span&gt; bugfix        &lt;span class="c"&gt;# Deletes the bugfix branch&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Comparing branches&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git log master..bugfix  &lt;span class="c"&gt;# Lists the commits in the bugfix branch not in master&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git diff master..bugfix   &lt;span class="c"&gt;# Shows the summary of changes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Stashing&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git stash push &lt;span class="nt"&gt;-m&lt;/span&gt; “New tax rules”     &lt;span class="c"&gt;# Creates a new stash&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git stash list                        &lt;span class="c"&gt;# Lists all the stashes&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git stash show stash@&lt;span class="o"&gt;{&lt;/span&gt;1&lt;span class="o"&gt;}&lt;/span&gt;              &lt;span class="c"&gt;# Shows the given stash&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git stash show 1                      &lt;span class="c"&gt;# shortcut for stash@{1}&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git stash apply 1                &lt;span class="c"&gt;# Applies the given stash to the working dir&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git stash drop 1                      &lt;span class="c"&gt;# Deletes the given stash&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git stash clear                       &lt;span class="c"&gt;# Deletes all the stashes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Merging&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git merge bugfix          &lt;span class="c"&gt;# Merges the bugfix branch into the current branch&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git merge &lt;span class="nt"&gt;--no-ff&lt;/span&gt; bugfix  &lt;span class="c"&gt;# Creates a merge commit even if FF is possible&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git merge &lt;span class="nt"&gt;--squash&lt;/span&gt; bugfix &lt;span class="c"&gt;# Performs a squash merge&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git merge &lt;span class="nt"&gt;--abort&lt;/span&gt;         &lt;span class="c"&gt;# Aborts the merge&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Viewing the merged branches&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git branch &lt;span class="nt"&gt;--merged&lt;/span&gt;       &lt;span class="c"&gt;# Shows the merged branches&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git branch &lt;span class="nt"&gt;--no-merged&lt;/span&gt;    &lt;span class="c"&gt;# Shows the unmerged branches&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Rebasing&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git rebase master         &lt;span class="c"&gt;# Changes the base of the current branch&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Cherry picking&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git cherry-pick dad47ed   &lt;span class="c"&gt;# Applies the given commit on the current branch&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  👥 &lt;strong&gt;&lt;em&gt;Collaboration&lt;/em&gt;&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Cloning a repository&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git clone url
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Syncing with remotes&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git fetch origin master          &lt;span class="c"&gt;# Fetches master from origin&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git fetch origin                 &lt;span class="c"&gt;# Fetches all objects from origin&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git fetch                        &lt;span class="c"&gt;# Shortcut for “git fetch origin” &lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git pull                         &lt;span class="c"&gt;# Fetch + merge&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git push origin master           &lt;span class="c"&gt;# Pushes master to origin&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git push                         &lt;span class="c"&gt;# Shortcut for “git push origin master”&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Sharing tags&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git push origin v1.0               &lt;span class="c"&gt;# Pushes tag v1.0 to origin&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git push origin —delete v1.0 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Sharing branches&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git branch &lt;span class="nt"&gt;-r&lt;/span&gt;                     &lt;span class="c"&gt;# Shows remote tracking branches&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git branch &lt;span class="nt"&gt;-vv&lt;/span&gt;                    &lt;span class="c"&gt;# Shows local &amp;amp; remote tracking branches&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git push &lt;span class="nt"&gt;-u&lt;/span&gt; origin bugfix         &lt;span class="c"&gt;# Pushes bugfix to origin&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git push &lt;span class="nt"&gt;-d&lt;/span&gt; origin bugfix         &lt;span class="c"&gt;# Removes bugfix from origin&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Managing remotes&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git remote                        &lt;span class="c"&gt;# Shows remote repos&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git remote add upstream url       &lt;span class="c"&gt;# Adds a new remote called upstream&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git remote &lt;span class="nb"&gt;rm &lt;/span&gt;upstream            &lt;span class="c"&gt;# Remotes upstream&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  📜 &lt;strong&gt;&lt;em&gt;Rewriting History&lt;/em&gt;&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Undoing commits&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git reset &lt;span class="nt"&gt;--soft&lt;/span&gt; HEAD^         &lt;span class="c"&gt;# Removes the last commit, keeps changed staged&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git reset &lt;span class="nt"&gt;--mixed&lt;/span&gt; HEAD^        &lt;span class="c"&gt;# Unstages the changes as well&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; HEAD^         &lt;span class="c"&gt;# Discards local changes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Reverting commits&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git revert 72856ea               &lt;span class="c"&gt;# Reverts the given commit&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git revert HEAD~3..              &lt;span class="c"&gt;# Reverts the last three commits  &lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git revert &lt;span class="nt"&gt;--no-commit&lt;/span&gt; HEAD~3..
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Recovering lost commits&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git reflog                       &lt;span class="c"&gt;# Shows the history of HEAD&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git reflog show bugfix           &lt;span class="c"&gt;# Shows the history of bugfix pointer&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Amending the last commit&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git commit &lt;span class="nt"&gt;--amend&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Interactive rebasing&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git rebase &lt;span class="nt"&gt;-i&lt;/span&gt; HEAD~5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>git</category>
      <category>github</category>
      <category>guide</category>
    </item>
    <item>
      <title>HTTP codes cheatsheet</title>
      <dc:creator>Dionis</dc:creator>
      <pubDate>Fri, 19 Aug 2022 08:55:00 +0000</pubDate>
      <link>https://dev.to/dionisuliu/http-codes-cheatsheet-1k89</link>
      <guid>https://dev.to/dionisuliu/http-codes-cheatsheet-1k89</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;What are HTTP status codes&lt;/em&gt;&lt;/strong&gt;❓&lt;/p&gt;

&lt;p&gt;An HTTP status code is &lt;strong&gt;a server response to a browser's request&lt;/strong&gt;. When you visit a website, your browser sends a request to the site's server, and the server then responds to the browser's request with a three-digit code: the HTTP status code.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔵 HTTP Status Codes
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;100&lt;/strong&gt; - &lt;strong&gt;Continue&lt;/strong&gt; — this status did the notification code that the server has received the first request and waits to receive further instructions from the browser.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;101&lt;/strong&gt; - &lt;strong&gt;Switching Protocols&lt;/strong&gt; — it is used when the server receives the changes proposed by the browser. For example, changes from HTTP 1.0 to HTTP 1.1.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;102&lt;/strong&gt; - &lt;strong&gt;Processing&lt;/strong&gt; — the server has received the request but has not completed it. This is to prevent the browser from interpreting that the request has been lost, but not yet completed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;103&lt;/strong&gt; - &lt;strong&gt;Checkpoint&lt;/strong&gt; — It is used to proceed with the request that was previously missing or cancelled.&lt;/p&gt;




&lt;h3&gt;
  
  
  🟢 HTTP Successful Codes
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;200&lt;/strong&gt; - &lt;strong&gt;OK&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;201&lt;/strong&gt; - &lt;strong&gt;Created&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;202&lt;/strong&gt; - &lt;strong&gt;Accepted&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;204&lt;/strong&gt; - &lt;strong&gt;No Content&lt;/strong&gt; — server precessed the request successfully, but there          is nothing to return&lt;/p&gt;




&lt;h3&gt;
  
  
  🟡 HTTP Redirection Codes
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;301&lt;/strong&gt; - &lt;strong&gt;Moved Permanently&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;302&lt;/strong&gt; - &lt;strong&gt;Moved Temporarily&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;304&lt;/strong&gt; - &lt;strong&gt;Not Modified&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;307&lt;/strong&gt; - &lt;strong&gt;Moved Temporarily&lt;/strong&gt; (preserves HTTP method)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;308&lt;/strong&gt; - &lt;strong&gt;Moved Permanently&lt;/strong&gt; (preserves HTTP method)&lt;/p&gt;




&lt;h3&gt;
  
  
  🔴 HTTP Client Error Codes :
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;400&lt;/strong&gt; - &lt;strong&gt;Bad Request&lt;/strong&gt; — the request was not understood, malformed request syntax, etc.&lt;/p&gt;

&lt;p&gt;💡 Check your request for a missing required parameter or an invalid query parameter value.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;401&lt;/strong&gt; - &lt;strong&gt;Unauthorised&lt;/strong&gt; — when authentication is required, but was not provided.&lt;/p&gt;

&lt;p&gt;💡 The provided API key is invalid or missing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;403&lt;/strong&gt; - &lt;strong&gt;Forbidden&lt;/strong&gt; — server is refusing action based on user not having necessary permissions for the resource.&lt;/p&gt;

&lt;p&gt;💡 The provided API key is invalid for the requested project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;404&lt;/strong&gt; - &lt;strong&gt;Not Found&lt;/strong&gt; — but may be available in the future (e.g. not existing user on specific ID).&lt;/p&gt;

&lt;p&gt;💡 The requested resource does not exist&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;405&lt;/strong&gt; - &lt;strong&gt;Method Not Allowed&lt;/strong&gt; — for example, when you do a POST request to a GET-only endpoint.&lt;/p&gt;

&lt;p&gt;💡 The requested HTTP method is not supported for the specified resource.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;406&lt;/strong&gt; - &lt;strong&gt;Not Acceptable&lt;/strong&gt; — generated data are in e different format than accepted by the client.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;408&lt;/strong&gt; - &lt;strong&gt;Request Timeout&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;409&lt;/strong&gt; - &lt;strong&gt;Conflict&lt;/strong&gt; — edit conflict between multiple simultaneous updates.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;410&lt;/strong&gt; - &lt;strong&gt;Gone&lt;/strong&gt; — similar to &lt;strong&gt;404&lt;/strong&gt;, but indicates that the resource won’t ever be available again.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;411&lt;/strong&gt; - &lt;strong&gt;Length Required&lt;/strong&gt; — request did not specify length of content.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;413&lt;/strong&gt; - &lt;strong&gt;Payload Too Large&lt;/strong&gt; — the request is larger than the server is willing to process.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;414&lt;/strong&gt; - &lt;strong&gt;URI Too Long&lt;/strong&gt; — typically when too many data are transferred via GET params.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;415&lt;/strong&gt; - &lt;strong&gt;Unsupported Media Type&lt;/strong&gt; — request contains data in wrong format.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;429&lt;/strong&gt; - &lt;strong&gt;Too Many Requests&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;💡 The rate limit for the API has been exceeded.&lt;/p&gt;




&lt;h3&gt;
  
  
  🟣 HTTP Server Error Codes
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;500&lt;/strong&gt; - &lt;strong&gt;To Many Requests&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;💡 The rate limit for the API has been exceeded.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;501&lt;/strong&gt; - &lt;strong&gt;Not Implemented&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;502&lt;/strong&gt; - &lt;strong&gt;Bad Gateway&lt;/strong&gt; — server acts as a proxy and received invalid response from the upstream server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;503&lt;/strong&gt; - &lt;strong&gt;Service Unavailable&lt;/strong&gt; — the server cannot temporarily process the request.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;504&lt;/strong&gt; - &lt;strong&gt;Gateway Timeout&lt;/strong&gt; — server acts as a proxy and did not receive a response from the upstream server in defined time frame.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;505&lt;/strong&gt; - &lt;strong&gt;HTTP Version Not Supported&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
      <category>node</category>
    </item>
  </channel>
</rss>
