Cpp Coding Standards/VIRTUAL/LSP

From Apache OpenOffice Wiki
Jump to: navigation, search

Liskov Substitution Principle (LSP)

See http://en.wikipedia.org/wiki/Liskov_substitution_principle.

This statement can be put into different wordings to view different aspects:

  • Everything you can do with a base class, you need to be able to do with any of its derived classes.
  • A derived class must not require more and must not promise less than its base class.
  • Overridden versions of virtual functions must not have stronger preconditions or weaker postconditions than the version of the base class.
  • The client of a base class must never need to know, which derived class it is using really.
Personal tools