<?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: Chisom Chima</title>
    <description>The latest articles on DEV Community by Chisom Chima (@thechisomchima).</description>
    <link>https://dev.to/thechisomchima</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%2F3697687%2Fa97a0001-1225-4a71-a855-cf8f9393dc8e.jpg</url>
      <title>DEV Community: Chisom Chima</title>
      <link>https://dev.to/thechisomchima</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/thechisomchima"/>
    <language>en</language>
    <item>
      <title>Design Patterns You’ll Actually Use: A No-Nonsense Guide</title>
      <dc:creator>Chisom Chima</dc:creator>
      <pubDate>Wed, 07 Jan 2026 07:17:10 +0000</pubDate>
      <link>https://dev.to/thechisomchima/design-patterns-youll-actually-use-a-no-nonsense-guide-4l3l</link>
      <guid>https://dev.to/thechisomchima/design-patterns-youll-actually-use-a-no-nonsense-guide-4l3l</guid>
      <description>&lt;p&gt;We have all been there. You start a project with the best intentions, but three months later, the codebase looks like a bowl of spaghetti. Changing one variable breaks five unrelated files, and "fixing" a bug feels like playing a dangerous game of Jenga.&lt;/p&gt;

&lt;p&gt;This is exactly why design patterns exist. They aren't just academic theories meant to make you sound smart in interviews. They are battle-tested strategies for keeping your code clean and your sanity intact.&lt;/p&gt;

&lt;p&gt;Here are the four patterns that every JavaScript developer should actually know.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Singleton (The "Only One" Rule)
&lt;/h2&gt;

&lt;p&gt;The Singleton is one of the simplest patterns to understand but also one of the most debated. The goal is simple: ensure a class has exactly one instance and provides a global point of access to it.&lt;/p&gt;

&lt;p&gt;Think of a Database Connection or a Theme Manager. You don't want five different objects trying to manage your dark mode settings at the same time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ThemeManager {
  constructor() {
    if (ThemeManager.instance) {
      return ThemeManager.instance;
    }

    this.theme = 'light';
    ThemeManager.instance = this;
  }

  toggleTheme() {
    this.theme = this.theme === 'light' ? 'dark' : 'light';
    console.log(`Theme is now ${this.theme}`);
  }
}

// Even if we try to create a new one, we get the same instance
const managerA = new ThemeManager();
const managerB = new ThemeManager();

console.log(managerA === managerB); // true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Pro Tip: Be careful with Singletons. They are essentially "global state," which can make testing a bit harder if you aren't careful. Use them only when you truly need a single source of truth.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The Factory Pattern (The Object Creator)
&lt;/h2&gt;

&lt;p&gt;In a big app, you often need to create different types of objects based on a specific condition. Instead of cluttering your main logic with a dozen &lt;code&gt;if/else&lt;/code&gt; or &lt;code&gt;switch&lt;/code&gt; statements, you use a Factory.&lt;/p&gt;

&lt;p&gt;Imagine you are building a notification system that handles Email, SMS, and Push notifications.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Email {
  send(msg) { console.log(`Sending Email: ${msg}`); }
}

class SMS {
  send(msg) { console.log(`Sending SMS: ${msg}`); }
}

class NotificationFactory {
  createNotification(type) {
    switch(type) {
      case 'email': return new Email();
      case 'sms': return new SMS();
      default: return null;
    }
  }
}

const factory = new NotificationFactory();
const service = factory.createNotification('email');
service.send('Hello World!');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This keeps your code "decoupled." The main part of your app doesn't need to know how an Email object is built; it just asks the factory for a notification service and goes to work.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Observer Pattern (The Subscriber)
&lt;/h2&gt;

&lt;p&gt;If you have ever used addEventListener in JavaScript, you have already used a version of the Observer pattern. It is all about "don't call me, I'll call you."&lt;/p&gt;

&lt;p&gt;One object (the Subject) keeps a list of other objects (Observers) that want to know when something happens. When the state changes, the Subject broadcasts a message to everyone on the list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Store {
  constructor() {
    this.subscribers = [];
  }

  subscribe(fn) {
    this.subscribers.push(fn);
  }

  unsubscribe(fn) {
    this.subscribers = this.subscribers.filter(item =&amp;gt; item !== fn);
  }

  broadcast(data) {
    this.subscribers.forEach(fn =&amp;gt; fn(data));
  }
}

const myStore = new Store();

const logger = (data) =&amp;gt; console.log(`Log: ${data}`);
const uiUpdater = (data) =&amp;gt; console.log(`Updating UI with: ${data}`);

myStore.subscribe(logger);
myStore.subscribe(uiUpdater);

// When something happens, everyone gets the update
myStore.broadcast('New product added!');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the backbone of state management libraries like Redux or the reactivity systems in Vue and React.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Strategy Pattern (The Plugin Approach)
&lt;/h2&gt;

&lt;p&gt;The Strategy pattern is a lifesaver when you have a specific task (like calculating a price) but there are multiple ways to do it. Instead of one massive function with a hundred arguments, you create separate "strategies."&lt;/p&gt;

&lt;p&gt;Let’s look at a payment processing example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Different strategies
const paypal = (amount) =&amp;gt; amount * 1.05; // 5% fee
const creditCard = (amount) =&amp;gt; amount + 2; // Flat $2 fee
const crypto = (amount) =&amp;gt; amount * 0.98; // 2% discount

class Order {
  constructor(amount) {
    this.amount = amount;
  }

  process(strategy) {
    return strategy(this.amount);
  }
}

const myOrder = new Order(100);
console.log(myOrder.process(paypal)); // 105
console.log(myOrder.process(crypto)); // 98
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The beauty here is that you can add a new payment method (like Apple Pay) just by writing a new small function. You don't have to touch the Order class at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Reality Check: Don't Over-Engineer
&lt;/h2&gt;

&lt;p&gt;Here is the most important advice I can give you: Don't use a pattern just to use a pattern.&lt;/p&gt;

&lt;p&gt;I have seen developers turn a 10-line file into a 200-line "Pattern Masterpiece" that no one can read. If a simple if statement works and it's readable, stick with the if statement.&lt;/p&gt;

&lt;p&gt;Patterns are tools for your belt. Use them when the code starts feeling heavy or hard to maintain.&lt;/p&gt;

&lt;p&gt;What’s your favorite pattern?&lt;br&gt;
Do you use these in your daily workflow, or do you think they add too much boilerplate? Let’s talk about it in the comments.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>codequality</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
