What is a better way of implementing ColorPoint to avoid problems with equals() method?
public class Point {
private final int x;
private final int y;
@Override public boolean equals(Object o) {
if (!(o instanceof Point))
return false;
Point p = (Point)o;
return p.x == x && p.y == y;
}
// Remainder omitted
}
public class ColorPoint extends Point {
private final Color color;
// Remainder omitted
}
Use composition, not inheritance:
public class ColorPoint {
private final Point point;
private final Color color;
// Remainder omitted
}
What is a better way of implementing ColorPoint to avoid problems with equals() method?
public class Point {
private final int x;
private final int y;
@Override public boolean equals(Object o) {
if (!(o instanceof Point))
return false;
Point p = (Point)o;
return p.x == x && p.y == y;
}
// Remainder omitted
}
public class ColorPoint extends Point {
private final Color color;
// Remainder omitted
}
What is a better way of implementing ColorPoint to avoid problems with equals() method?
public class Point {
private final int x;
private final int y;
@Override public boolean equals(Object o) {
if (!(o instanceof Point))
return false;
Point p = (Point)o;
return p.x == x && p.y == y;
}
// Remainder omitted
}
public class ColorPoint extends Point {
private final Color color;
// Remainder omitted
}
Use composition, not inheritance:
public class ColorPoint {
private final Point point;
private final Color color;
// Remainder omitted
}
status | not learned | measured difficulty | 37% [default] | last interval [days] | |||
---|---|---|---|---|---|---|---|
repetition number in this series | 0 | memorised on | scheduled repetition | ||||
scheduled repetition interval | last repetition or drill |