Liskov Substitution Principle (LSP)

A subclass can be substitutable for its superclass. Making it compatible with the superclass and can be used for polymorphism.

It should uphold all invariants and functionalities as the superclass.

Contra-variance Problem: https://piazza.com/class/lh4qjengjtl5zy/post/736

  • Happens wherever we have a binary operator where the other parameter is the same type as *this.

Solution: Either restructure hierarchy or apply Template Method Pattern or Visitor Pattern. Allow subclasses to customize portions of this method by performing overrides.