public interface INumber {
public INumber add(INumber other);
}
public class RomanNumber implements INumber {
public RomanNumber add(INumber other) {
// when `other` is not a RomanNumber
// convert other to RomanNumber
// add `other` to `this`
}
}
public class HexadecimalNumber implements INumber {
public HexadecimalNumber add(INumber other) {
// convert other to HexadecimalNumber and add...
}
}
public abstract class Number {
public abstract Integer toDecimal();
public abstract Number fromDecimal(Integer);
public Number add(Number other) {
returh fromDecimal(this.toDecimal() + other.toDecimal());
}
}
public class RomanNumber extends Number {
public Integer toDecimal() {
// convert `this` to Integer
}
public RomanNumber fromDecimal(Integer n) {
// convert `n` to RomanNumber
}
}
public class HexadecimalNumber extends Number {
public Integer toDecimal() {
// convert `this` to Integer
}
public HexadecimalNumber fromDecimal(Integer n) {
// convert `n` to HexadecimalNumber
}
}
Vector2d implements IVector { // THIS IS NOT A CONSTRUCTOR! @Override public void Vector() { } } ```
<p>and compare it to this:</p>
```java public abstract class BaseVector { public abstract BaseVector() { } } public class Vector2d extends
BaseVector { public Vector2d() { // now it DOES HAVE a default constructor super(); } } ```