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: Refactoring 030 – How to Avoid Accidental Redundancy | 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 > Refactoring 030 – How to Avoid Accidental Redundancy | HackerNoon
Computing

Refactoring 030 – How to Avoid Accidental Redundancy | HackerNoon

News Room
Last updated: 2025/07/13 at 3:59 PM
News Room Published 13 July 2025
Share
SHARE

Avoid accidental redundancy

TL;DR: Don’t pass attributes your object already owns

Problems Addressed 😔

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xxxviii

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xxxv

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-ii-o96s3wl4

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-x-i7r34uj

https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xxix

Steps 👣

  1. Identify methods that receive owned attributes
  2. Remove those parameters from the method signature
  3. Replace usage with direct access to the attribute
  4. Rename the method if needed to match the new intention

Sample Code 💻

Before 🚨

class Auto {
  constructor(motor) {
    this.motor = motor
  }

  startEngine(motor) {
    motor.ignite()
  }
}

// Usage
const motor = new Motor()
const auto = new Auto(motor)

auto.startEngine(motor)
// Redundant and maybe inconsistent

After 👉

class Auto {
  constructor(motor) {
    this.motor = motor
  }
    
  // 1. Identify methods that receive owned attributes    
  startEngine() {
    // 2. Remove those parameters from the method signature  
    // 4. Rename the method if needed to match the new intention
    this.motor.ignite()
  }
}

// Adjust usage to call without passing motor
const motor = new Motor()
const auto = new Auto(motor)

// 3. Replace usage with direct access to the attribute  
auto.startEngine() // No parameter needed

Type 📝

Safety 🛡️

This refactoring is straightforward and safe if you have good test coverage.

Why is the Code Better? ✨

You remove accidental complexity.

You stop pretending your method needs information from the outside.

You reduce the cognitive load and improve encapsulation.

You clarify which attributes are essential.

You avoid passing the same data through different paths.

You reduce parameter redundancy and simplify method signatures.

You eliminate the possibility of passing inconsistent values since methods now directly access the object’s state.

This makes the code more maintainable and reduces the cognitive load when reading method calls.

The methods become more cohesive by relying on their own object’s data rather than external parameters.

How Does it Improve the Bijection? 🗺️

This refactoring enhances the Bijection by aligning object behavior more closely with real-world entities.

You match the real-world concept: an object uses what it owns.

You improve the anthropomorphism and avoid unrealistic indirection.

You also reduce internal and external coupling.

Limitations ⚠️

This works only if the method always uses the internal attribute.

If you need to inject different versions for testing or variations, consider using dependency injection or a strategy pattern.

Refactor with AI 🤖

Suggested Prompt: 1. Identify methods that receive owned attributes 2. Remove those parameters from the method signature 3. Replace usage with direct access to the attribute 4. Rename the method if needed to match the new intention

Level 🔋

  • Remove Parameter
  • Introduce Parameter Object

Credits 🙏

Image by F. Muhammad on Pixabay


This article is part of the Refactoring Series.

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 Costco trials ‘dangerous’ change to popular food item as chain ‘listens’ to fans
Next Article Brenda, 95, and her soft toys become unlikely stars on TikTok
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

Study warns of ‘significant risks’ in using AI therapy chatbots | News
News
The Show’s Almost Over for These Outstanding Prime Day Projector Deals
News
Best Shark robot vacuum Prime Day deal: Save $400 right now
News
‘The bottom turtle’: Amazon’s storage workhorse is getting an AI upgrade – News
News

You Might also Like

Computing

EU starts customs registration of Chinese EVs for potential retroactive tariffs · TechNode

1 Min Read
Computing

TSMC hauled in subsidies of $1.51 billion from China and Japan · TechNode

4 Min Read
Computing

Huawei may launch flagship P70 series smartphone without press conference · TechNode

1 Min Read
Computing

Douyin to enter offline payment field with $190 million purchase of third-party license · 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?