Liskov substitution principle
You should be able to replace any reference to a base class with a derived class and the program should still work
Guiding the use of inheritance
Two subclasses of License, both can be substituted for ay reference to License and the billing system still works - it does not depend on the details
The Square/Rectangle problem
A square is not a proper subtype of a rectangle since a rectangle can have the height and width set independently - the square adds an additional constraint. In this situation the client would need to check the specific type of the object to see if it will behave appropriately
LSP and architecture
In the beginning of OO the LSP was used to guide the construction of type hierarchies. Now it has been extended to any kind of interface an implementation e.g. REST
Example LSP violation
Aggregator for taxi dispatch services.
When we find an appropriate driver for the user we dispatch a PUT to the specific companies' server.
I don't know why he's put the parameters in the URL, but at least it's not a GET
purplecab.com/driver/Bob
/pickupAddress/24 Maple St.
/pickupTime/153
/destination/ORD
All the companies need to implement the same specification - then we can just swap out the url. But the Acme company implemented the spec wrong - abbreviating destination to dest. And:
Acme is the largest taxi company in our area, and Acme’s CEO’s ex-wife is our CEO’s new wife, and …
We need to add a special case to handle acme, and construct the dispatch request differently.
if (driver.getDispatchUri().startsWith("acme.com"))...
Hard coding acme into the code like this is a bad idea. We need to add a new dispatch command creation module with configuration data, which would be unnecessary if the LSP was not violated
Acme.com /pickupAddress/%s/pickupTime/%s/dest/%s
*.* /pickupAddress/%s/pickupTime/%s/destination/%s