Urgent.News

What's breaking now, across thousands of outlets.

Tech

Code Smell 321 - Getter Piggybacking

Don't reuse an existing getter to bolt on new business logic from outside the object.

Code Smell 321 - Getter Piggybacking

Getter piggybacking occurs when an existing getter is repurposed to handle new business logic outside of the original object. This leads to issues such as duplicated business rules, broken encapsulation, scattered comparison logic, hidden domain knowledge, and fragile refactoring.

For example, consider a `Food` class that exposes a `useByDate` getter for displaying its use-by date. Later, a function called `removeExpiredFood` needs to filter out expired food items, so it reuses the `useByDate` getter and performs a comparison against the current date. Another function called `flagNearExpiryFood` also needs to check if food is near its expiry date, so it calls `useByDate` and writes its own slightly different comparison logic. Now, two functions are deciding what "expired" means, neither of which is the `Food` object itself.

This violates the principle of encapsulation and leads to fragile code that is difficult to maintain. The recommended solution is to add a real method to the object that encapsulates the business logic, such as an `isExpiredOn` method. This way, the logic is contained within the object and all callers share the same implementation. Getters should only be used for rendering purposes, not for carrying out complex business logic.

Written by urgent.news from HackerNoon's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at hackernoon.com →

More in Tech

Put Your Docker Images on a Diet with Alpine Linux (2015)

Archival repost — originally published on my old blog on June 21, 2015, back when Alpine was still a dark-horse pick rather than the default.

  • Alpine Linux used as Docker image base to reduce size
  • Popular Docker base images like Ubuntu and Debian heavy
  • Alpine Linux popularity increased rapidly among Docker users

How to Configure Full Parallel Execution in TestNG via Maven (with Dynamic Thread Control)

Running automation test suites sequentially can quickly become a bottleneck in CI/CD pipelines. To optimize execution efficiency, you can enable full parallel execution using TestNG and Maven…

  • Update testngregression.xml for parallel mode and thread count
  • Configure pom.xml for dynamic control with maven-surefire-plugin
  • Override settings via Maven command-line parameters for runtime control

scripting et réseaux

OK j'avance sur le script, si j'ai bien compris. Bash c'est pour du petit script rapide et Python quand c'est un peu plus complexe (et idéalement on script dans le language où le script va agir.

  • Bash is best for small scripts, while Python handles complex tasks
  • Networking concepts like IP addresses and ports are challenging to visualize
  • Author plans to learn via online courses by January and document progress

85 Container. 1 Entwickler.

85 Container, 24 Datenbanken, 232 Cron-Jobs — und ein Gründer Wenn ich jemandem sage, dass ich alleine arbeite, kommt meistens dieselbe Reaktion: Ungläubiges Staunen, gefolgt von der Frage, wie das…

  • Founder built system with 85 containers, 24 databases, and 232 automated tasks
  • System completed 1,087 tasks with 88% success rate after 14 months
  • Founder emphasizes automating right tasks, using Guard-Regels for clear boundaries

More from Saturday 22 August →