By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
World of SoftwareWorld of SoftwareWorld of Software
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Search
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright © All Rights Reserved. World of Software.
Reading: Code Smell 319 – Hardcoded Stateless Properties | HackerNoon
Share
Sign In
Notification Show More
Font ResizerAa
World of SoftwareWorld of Software
Font ResizerAa
  • Software
  • Mobile
  • Computing
  • Gadget
  • Gaming
  • Videos
Search
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Have an existing account? Sign In
Follow US
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright © All Rights Reserved. World of Software.
World of Software > Computing > Code Smell 319 – Hardcoded Stateless Properties | HackerNoon
Computing

Code Smell 319 – Hardcoded Stateless Properties | HackerNoon

News Room
Last updated: 2026/04/12 at 6:00 PM
News Room Published 12 April 2026
Share
Code Smell 319 – Hardcoded Stateless Properties | HackerNoon
SHARE

Don’t turn collaborators into permanent roommates

TL;DR: You should avoid storing stateless utility classes as instance variables initialized with new.

Problems 😔

  • Hardcoded dependencies
  • Testing difficulties
  • High coupling
  • Hidden side effects
  • Rigid design
  • Misleading intent
  • Premature Optimization
  • Stack clutter

Solutions 😃

  1. Use dependency injection
  2. Pass as parameter
  3. Use static methods
  4. Inline the logic
  5. Use local variables
  6. Inline object creation

Refactorings ⚙️

https://hackernoon.com/refactoring-024-replace-global-variables-with-dependency-injection?embedable=true

https://hackernoon.com/refactoring-030-how-to-avoid-accidental-redundancy?embedable=true

https://hackernoon.com/refactoring-007-the-refactor-that-reveals-missing-concepts?embedable=true

Context 💬

Hardcoding a stateless class in the constructor creates permanent coupling.

Even if the class is cheap to instantiate, you lose the ability to swap it.

Stateless objects shouldn’t be part of the object’s internal state.

You confuse readers by making a tool look essential to the object’s identity.

It makes testing harder because you can’t mock the hardcoded dependency.

Sample Code 💻

Wrong 🚫

class UserProcessor {
  private provider: MockDataProvider;

  constructor() {
    // You hardcode the dependency here.
    // This makes the class harder to test.
    this.provider = new MockDataProvider();
  }

  process(data: any) {
    return this.provider.format(data);
  }
}

Right 👉

interface DataProvider {
  format(data: any): any;
}

class UserProcessor {
  // You inject the dependency via constructor.
  // Now you can swap it or mock it easily.
  constructor(private readonly provider: DataProvider) {}

  process(data: any) {
    return this.provider.format(data);
  }
}
// Simpler but coupled
 class UserProcessor {
    constructor() {
      // Empty
    }

    process(data: any) {
      return new MockDataProvider().format(data);
    }
  }

Detection 🔍

Look for the new keyword inside constructors.

Watch for private properties instantiated directly in the constructor rather than passed as parameters.

Most linters flag this pattern automatically when you create instances and assign them to private fields.

Tags 🏷️

  • Premature Optimization

Level 🔋

[X] Beginner

Why the Bijection Is Important 🗺️

Software should mimic a MAPPER of the real world.

In reality, a worker might use a tool to complete a task.

The tool is not a permanent physical attachment to the worker.

When you refactor to use dependency injection, you respect the bijection by treating collaborators as external entities, not internal state.

This keeps your simulation flexible and accurate.

AI Generation 🤖

AI generators frequently create this smell.

They often suggest code that just works by instancing dependencies directly in the constructor to save time.

AI Detection 🧲

AI can easily detect this smell without explicit instructions.

When you show AI a class with new keywords in the constructor, it recognizes the pattern as hardcoded coupling.

AI identifies that stateless utility classes should be injected rather than instantiated internally.

The detection is straightforward because the pattern is syntactically obvious and semantically harmful.

Try Them! 🛠

Remember: AI Assistants make lots of mistakes

Suggested Prompt: remove the cached attribute

Without Proper Instructions 📵

  • ChatGPT
  • Claude
  • Perplexity
  • Copilot
  • You
  • Gemini
  • DeepSeek
  • Meta AI
  • Grok
  • Qwen

With Specific Instructions 👩‍🏫

  • ChatGPT
  • Claude
  • Perplexity
  • Copilot
  • You
  • Gemini
  • DeepSeek
  • Meta AI
  • Grok
  • Qwen

Conclusion 🏁

Storing stateless dependencies as instance variables makes your code rigid.

When you inject these dependencies instead, you improve testability and keep your objects focused on their true purpose.

Relations 👩‍❤️‍💋‍👨

https://hackernoon.com/code-smell-06-trying-to-be-a-clever-programmer?embedable=true

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-iv-7sc3w8n?embedable=true

More Information 📕

https://hackernoon.com/coupling-the-one-and-only-software-designing-problem-9z5a321h?embedable=true

Disclaimer 📘

Code Smells are my opinion.

Credits 🙏

Photo by Possessed Photography on Unsplash


Coupling is the enemy of change

Rich Hickey

https://hackernoon.com/400-thought-provoking-software-engineering-quotes?embedable=true


This article is part of the CodeSmell Series.

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-i-xqz3evd?embedable=true

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Twitter Email Print
Share
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Previous Article How Often Should You Restart Your Phone? – BGR How Often Should You Restart Your Phone? – BGR
Next Article Ceasefire on the Ground, Cyberwar Online: Inside This Week’s Surge in Hacks and Scams Ceasefire on the Ground, Cyberwar Online: Inside This Week’s Surge in Hacks and Scams
Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Stay Connected

248.1k Like
69.1k Follow
134k Pin
54.3k Follow

Latest News

Geely-backed flying car startup Aerofugia raises undisclosed Series B funding · TechNode
Geely-backed flying car startup Aerofugia raises undisclosed Series B funding · TechNode
Computing
Apple Reportedly Testing AI Glasses in Several Frame Styles
Apple Reportedly Testing AI Glasses in Several Frame Styles
News
Trump officials may be encouraging banks to test Anthropic’s Mythos model |  News
Trump officials may be encouraging banks to test Anthropic’s Mythos model | News
News
China is building a tunnel under the sea for its high speed. It has already reached a record depth
China is building a tunnel under the sea for its high speed. It has already reached a record depth
Mobile

You Might also Like

Geely-backed flying car startup Aerofugia raises undisclosed Series B funding · TechNode
Computing

Geely-backed flying car startup Aerofugia raises undisclosed Series B funding · TechNode

2 Min Read
Pinterest Affiliate Marketing That Pays: My Non-Spam Workflow, Step-by-Step
Computing

Pinterest Affiliate Marketing That Pays: My Non-Spam Workflow, Step-by-Step

13 Min Read
SEO Isn’t Dead But Your Strategies Have to Change | HackerNoon
Computing

SEO Isn’t Dead But Your Strategies Have to Change | HackerNoon

0 Min Read
Zhipu AI partners with Didi to develop AGI-based mobility agents · TechNode
Computing

Zhipu AI partners with Didi to develop AGI-based mobility agents · TechNode

1 Min Read
//

World of Software is your one-stop website for the latest tech news and updates, follow us now to get the news that matters to you.

Quick Link

  • Privacy Policy
  • Terms of use
  • Advertise
  • Contact

Topics

  • Computing
  • Software
  • Press Release
  • Trending

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

World of SoftwareWorld of Software
Follow US
Copyright © All Rights Reserved. World of Software.
Welcome Back!

Sign in to your account

Lost your password?