冗赘的元素
Program elements (like classes and functions) no longer provide enough value to justify their existence and should be inlined or removed.
Program elements such as classes and functions can add structure to code, supporting change, promoting reuse, or simply providing better names. But sometimes we really don't need that extra layer of structure. There might be a function whose name looks exactly the same as its implementation code, or a class that is essentially just a simple function.
Lazy elements often arise because a programmer expected a function or class to grow and become more complex someday, but that day never came. Or perhaps the class was originally useful but became smaller and smaller through refactoring until only one function remained. Whatever the reason, such program elements should be retired gracefully. The key is to maintain only the structure that actually adds value to the codebase.
// Lazy class - only one meaningful methodclass Logger {public void log(String message) {System.out.println(message); // Only one line of meaningful code}}// Lazy function - name is the same as implementationclass MathUtils {public static int add(int a, int b) {return a + b; // Function name says exactly what the code does}public static boolean isPositive(int number) {return number > 0; // Obvious implementation}}// Simplified class after refactoring - now too simpleclass Logger {public void log(String message) {System.out.println(message); // Only one line of meaningful code}}// Lazy utility class with obvious methodsclass StringHelper {public static boolean isEmpty(String str) {return str == null || str.isEmpty(); // Could be inlined}public static String toUpperCase(String str) {return str.toUpperCase(); // No additional logic}}// Service class with only one methodclass PasswordHasher {public String hash(String password) {return "hashed_" + password; // Simplified implementation}// Single responsibility, but maybe too simple to warrant a separate class}