发散式变化
A class needs to be modified frequently for different, unrelated reasons.
When a class needs to be modified for many different reasons, you've encountered Divergent Change. This violates the Single Responsibility Principle (SRP) and indicates the class is doing too much.
This class changes for different reasons: payroll rules, tax regulations, reporting formats, database schema, etc. Responsibilities should be split so each class handles only one axis of change.
class Employee {private String name;private double salary;private String department;private String address;private String email;// Needs to be modified due to payroll policy changespublic double calculatePay() {if ("Engineering".equals(department)) {return salary * 1.2;} else if ("Sales".equals(department)) {return salary * 1.1;} else if ("Management".equals(department)) {return salary * 1.5;}return salary;}// Needs to be modified due to tax law changespublic double calculateTax() {double pay = calculatePay();if (pay > 100000) {return pay * 0.35;} else if (pay > 50000) {return pay * 0.25;}return pay * 0.15;}// Needs to be modified due to report format changespublic String generateReport() {return "Employee: " + name +"\nDepartment: " + department +"\nPay: " + String.valueOf(calculatePay()) +"\nTax: " + String.valueOf(calculateTax());}// Needs to be modified due to database structure changespublic void saveToDatabase() {// Database save logicSystem.out.println("Saving to database...");}// Needs to be modified due to email system changespublic void sendPayslip() {System.out.println("Sending payslip to: " + this.email);}// Getters and setters - may change due to data format requirementspublic String getName() { return name; }public void setName(String name) { this.name = name; }public String getEmail() { return email; }public void setEmail(String email) { this.email = email; }public String getAddress() { return address; }public void setAddress(String address) { this.address = address; }}