Now we have the test, let's implement the code
public class Money {
// ... all the previous code
public boolean equals(Object anObject) {
if (anObject instanceof Money) {
Money aMoney= (Money)anObject;
return aMoney.currency().equals(currency())
& & amount() == aMoney.amount();
}
return false;
}
- Money is a value object, must first check it is of the
correct type, and then check the inside values.
- go back and check we have handled all cases in the test.
previous |
start |
next .... [Slide 7] ....