{
  "id": 2559764,
  "title": "Code Smell 321 - Getter Piggybacking",
  "url": "https://urgent.news/2026/08/22/code-smell-321-getter-piggybacking",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-08-22T09:14:12.000Z",
  "source": {
    "name": "HackerNoon",
    "slug": "hackernoon",
    "url": "https://hackernoon.com/code-smell-321-getter-piggybacking?source=rss"
  },
  "original_language": "en",
  "account": "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.\n\nFor 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.\n\nThis 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.",
  "summary": "Don't reuse an existing getter to bolt on new business logic from outside the object.",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}