Created
February 21, 2026 01:04
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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