This example demonstrates full power of Angelika Langer solution by adding extra classes Point3D and ColorPoint3D. They form two separate hierarchy branches and despite this extra complication we are able to match them equal when common fields are equal and specific fields having default values. That is ColorPoint3D(2,3,0,Color.TRANSPARENT) is equal ColorPoint(2,3,Color.TRANSPARENT) or Point(2,3) or Point3D(2,3,0).
Full mixed type equals() variant - in this case we genuinely assume that Point and ColorPoint can be genuinely equal when (explicitly) colorless ColorPoint is equals to (intrinsicly) colorless Point. This assume that every (extra) value component (color in ColorPoint) has default value (colorless color) making comparing subclass to superclass possible even when subclass have extra value components.
This solution is fully and unarguably and 100% Liskov Substitution Principle compliant.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|