<?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: Rafi Uzzaman</title>
    <description>The latest articles on DEV Community by Rafi Uzzaman (@rafiuzzaman).</description>
    <link>https://dev.to/rafiuzzaman</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4039479%2F936cd612-9c98-4a3f-a643-238f4bbdbd3f.jpeg</url>
      <title>DEV Community: Rafi Uzzaman</title>
      <link>https://dev.to/rafiuzzaman</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rafiuzzaman"/>
    <language>en</language>
    <item>
      <title>I thought adding one query parameter would take few minutes</title>
      <dc:creator>Rafi Uzzaman</dc:creator>
      <pubDate>Wed, 22 Jul 2026 06:23:47 +0000</pubDate>
      <link>https://dev.to/rafiuzzaman/i-thought-adding-one-query-parameter-would-take-few-minutes-284h</link>
      <guid>https://dev.to/rafiuzzaman/i-thought-adding-one-query-parameter-would-take-few-minutes-284h</guid>
      <description>&lt;p&gt;For the last few years I never really cared much about design patterns. My code worked. Features shipped. Why make it complicated?&lt;/p&gt;

&lt;p&gt;Then I got a task on a part of our production code that I had not worked on for almost a year. Add one more query parameter to a search module. I thought easy, few minutes, maybe less.&lt;/p&gt;

&lt;h2&gt;
  
  
  I opened the file
&lt;/h2&gt;

&lt;p&gt;There were already six if-else branches. One searched by name. Another by stock. Another by tax. Another by rack. Each one had been added at a different time for a different requirement. Each one worked fine on its own.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fofzlg227o0m74za4t4mz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fofzlg227o0m74za4t4mz.png" alt="If-else code block example" width="799" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before I wrote a single line for my new parameter, I had questions stuck in my head. Which branch does this belong to? Will this break something already working? Is this same logic sitting somewhere else too?&lt;/p&gt;

&lt;p&gt;Those few minutes turned into almost an hour. And I had not written any code yet. I was just reading.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The query parameter was not the difficult part.&lt;/p&gt;

&lt;p&gt;Finding the right place for it was.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The real problem
&lt;/h2&gt;

&lt;p&gt;The task itself was never hard. Understanding where it belonged was hard.&lt;/p&gt;

&lt;p&gt;Each branch existed for a real reason. Nobody did anything wrong adding them one at a time. But six branches in, the file had become a place where every new feature meant touching code that already worked. Small change, real risk, every time.&lt;/p&gt;

&lt;h2&gt;
  
  
  The change
&lt;/h2&gt;

&lt;p&gt;I pulled each search into its own strategy class. A resolver picks the right one and runs it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5s1eicnf2ykziwnpru5j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5s1eicnf2ykziwnpru5j.png" alt="Strategy version code" width="800" height="151"&gt;&lt;/a&gt;&lt;br&gt;
Now a new search type means writing one new class. Not touching the five that already work.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Foi6eductrqi6o5bz2y6j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Foi6eductrqi6o5bz2y6j.png" alt="Before and After comparison diagram" width="800" height="398"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I liked this approach
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Adding a new type does not mean editing an existing, working method&lt;/li&gt;
&lt;li&gt;Testing one search type means testing one small class, nothing else&lt;/li&gt;
&lt;li&gt;Reading one class to understand it, not the whole file&lt;/li&gt;
&lt;li&gt;The service just picks the right strategy, it does not need to know how each one works internally&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  One thing I learned
&lt;/h2&gt;

&lt;p&gt;You don't need to know pattern names to feel this problem. You just need to notice the feeling, too much to read before I can add my small thing. That feeling is the signal. The name comes after.&lt;/p&gt;

&lt;p&gt;I am not saying this is the only right way to do it. It is what worked for what I had.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next
&lt;/h2&gt;

&lt;p&gt;Once this was split up, I noticed the database queries inside each piece were nearly identical, just copy-pasted with small changes. That's the next one.&lt;/p&gt;

</description>
      <category>node</category>
      <category>typescript</category>
      <category>refactoring</category>
      <category>designpatterns</category>
    </item>
  </channel>
</rss>
