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

AVVERIFIER Outpaces Mythril and ETHBMC in Smart Contract Vulnerability Detection | HackerNoon
Computing
How I use Synology and Google Photos to build the perfect photo backup system
News
Chinese-made iPhones could be banned in US over theft of trade secrets
News
Deepfakes. Fake Recruiters. Cloned CFOs β€” Learn How to Stop AI-Driven Attacks in Real Time
Computing

You Might also Like

Computing

AVVERIFIER Outpaces Mythril and ETHBMC in Smart Contract Vulnerability Detection | HackerNoon

11 Min Read
Computing

Deepfakes. Fake Recruiters. Cloned CFOs β€” Learn How to Stop AI-Driven Attacks in Real Time

3 Min Read
Computing

Hyprland 0.50 Released With New Render Scheduling, Drops Legacy Renderer

2 Min Read
Computing

Douyin pushes further into travel with subsidy campaign, as competition among online platforms across sectors intensifies Β· TechNode

4 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?