Code Smell of the year

Divergent Change

It is not always ideal to conduct a refactoring with delegation. Split it completely, that the account class has no knowledge at all of the xml serialization as a result.

public class Account{

    private int accountNumber;
    private double balance = 0;

    public Account (int accountNumber){
        this.accountNumber = accountNumber;
    }

    public int getAccountNumber(){}
    public double getBalance(){}
    
    public void credit(double amount) {
        balance += amount;    
    }

    public void debit(double amount) {
        balance -= amount;
    }
    
    public String toXml () {
        return "<account><id>" + Integer.toString(getAccountNumber() + "</id>" +
                "<balance>" + Double.toString(getBalance()) + "</balance><account>";
    } 

}

You can fork it here from Github.

This is step five of the second part of the Refactoring kickstart beginner series. Here is step 6.