Lisksov Substitution Principle
LSP原則主要有兩種規格定義:
- If for each object to o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2 then S is a subtype of T.
如果對每一個型別為S的物件o1, 都有型別為T的物件o2, 使得以T定義的所有程式p在所有的物件o1都替換成o2時, 程式P的行為沒有發生變化, 那麼型別S就是行別T的子型別. - Functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it.
所有參照基礎類別的地方必須能透明地使用其衍生類別的物件.