Skip to content

Instantly share code, notes, and snippets.

@mcsee
Created February 21, 2026 01:04
Show Gist options
  • Select an option

  • Save mcsee/319a76a22fbb375f427d21ff9506ed78 to your computer and use it in GitHub Desktop.

Select an option

Save mcsee/319a76a22fbb375f427d21ff9506ed78 to your computer and use it in GitHub Desktop.
This gist belongs to the Clean Code Cookbook https://cleancodecookbook.com by Maximiliano Contieri https://maximilianocontieri.com
// File: Translator.java
// Step 2: Create a domain interface
public interface Translator {
String translate(String key);
}
// File: NearEarthObject.java
public class NearEarthObject {
private double energy;
private double probability;
// Step 3: Accept the interface as a parameter
public String getStatusDescription(Translator translator) {
int level = calculateTorinoLevel();
String key = "LEVEL_" + level;
// Step 4: Replace the global call with the parameter
return translator.translate(key);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment