Repeated Switch

noun

say it: “rih-PEE-tid SWICH” /rɪˈpitɪd swɪtʃ/

The same switch or if chain on a kind of thing, copied into several places in a program.

What is a repeated switch?

A repeated switch is a code smell: the same switch (or if chain) on a kind of thing, such as a gym class's type, copied into several places. Each copy decides what the kind means, so adding a new kind means finding every copy, and the one that's missed answers quietly with a wrong default. The cure gives the decision one home: polymorphism, or a dictionary from each kind to its values.

In a sentence

  • “Pilates was free to drop in on because one copy of the repeated switch never heard about it.”

Level: Journeyman · More Software Development terms at this level

Updated