Tramp Data — Code Smells Catalog Skip to content

Tramp Data

Data Dealers Data Code SmellDesign Smell Between Class

Data hitchhiking through a chain of methods that never use it. Each function accepts the parameter, ignores it, and passes it along — just so the one at the end of the line can finally read it.

2 min read 2 sources

Overview

This is very similar to the Message Chains code smell, but with the difference that there, the pizza supplier was ordered to go through a long chain of method calls. Here, the pizzeria supplier additionally delivers “pizza” through that long chain of method calls, with “pizza” present in each of the method parameters. This is an indicator of Dubious Abstraction code smell - the data that pass through long chains of calls, most likely at least one of the levels, are not consistent with the abstraction presented by each of the routine interfaces. [1]

Causation

This can happen due to a cheap way of Global Data code smell refactorization.

Problems

Law of Demeter Principle Violation

The functionality should be as close to the data it uses as possible. This doesn't seem to be the case when Tramp Data is present.

Example

Smelly
1class Game:
2    timer: int
3    match: Match
4
5    def start_turn():
6        match(timer).field(timer).players(timer).troops(timer)
PYTHON

Exceptions

In the context of the system as a whole, some communication between modules must take place. All possibilities should be properly balanced so that none of the smells dominate (Global Data, Tramp Data, Message Chain, Middle Man) to make the entire codebase as straightforward as possible.

---

Refactoring

  • Extract Method
  • Hide Delegate
  • Move Method

Sources

Browse All 56 Smells