public interface IndexedObject {public String toString();} class RomanIndexedObject implements IndexedObject { private int _i;
public interface IndexedObject {public String toString();} class RomanIndexedObject implements IndexedObject { class LetterIndexedObject implements IndexedObject { As you can see, there is code duplication. Rewrite it to remove the duplication
private int _i;
private Object _o;
RomanIndexedObject(int i, Object o) { _i = i; _o = o; }
public String toString() {
return indexToString() + _o.toString();
}
private String indexToString() {
return Util.toRoman(_i);
}
}
private int _i;
private Object _o;
LetterIndexedObject(int i, Object o) { _i = i; _o = o; }
public String toString() {
return indexToString() + _o.toString();
}
private String indexToString() {
return Util.toLetter(_i);
}
}
Expert Answer
To remove the code duplication in the RomanIndexedObject and LetterIndexedObject classes, you can cr…
OR