纯数据类
The class only contains fields and accessor methods and has no other functionality.
A Data Class contains only data and simple accessor methods, with no behavior. Such classes often indicate that behavior has been placed in the wrong location.
The Customer class is merely a data container; related business behavior should be moved into the Customer class so that data and behavior stay together.
class Customer {private String name;private String email;private String address;private double creditLimit;// Only getters and setters, no other behaviorpublic 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; }public double getCreditLimit() { return creditLimit; }public void setCreditLimit(double creditLimit) { this.creditLimit = creditLimit; }}// Behavior is placed in other classesclass CustomerService {public boolean canPurchase(Customer customer, double amount) {return customer.getCreditLimit() >= amount;}public void updateCreditLimit(Customer customer, double newLimit) {customer.setCreditLimit(newLimit);}}