The solution is simple. Ensure that equality is compare always in one set direction. This way symmetry contract is enforced. If compared class is subclass of this class, not same class but a subclass, the simply reverse direction by calling equals() on the compared object. Subclass has always better knowledge what and how it needs to be compared, it know about all extra fields.
Restricted mixed type equals() - in this case we genuinely assume here that ColorPoint of any color is not equal intrinsicly colorless Point even if they have got the same coordinates. However any class extending Point but not adding value component should be equal having the same coordinates. In that sense it is Liskov Substitution Principle compliant.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|