Liskov Substitution Principle

When PDFReportGenerator is redesigned to honor the superclass contract, it can be passed anywhere a ReportGenerator is expected and will behave reliably. A canonical example of an LSP violation is a Penguin subclass of Bird, because caller…

1 sources - 4 claims

When PDFReportGenerator is redesigned to honor the superclass contract, it can be passed anywhere a ReportGenerator is expected and will behave reliably. A canonical example of an LSP violation is a Penguin subclass of Bird, because callers that expect birds to fly will break when given a Penguin. The Liskov Substitution Principle requires that objects of a subclass must be substitutable for objects of their superclass without altering program correctness, meaning the subclass must honor the full behavioral contract of its parent. A PDFReportGenerator subclass that throws errors when used as a ReportGenerator violates LSP and defeats the purpose of inheritance.